NexusFi: Find Your Edge


Home Menu

 





Multi Time Frames - Ninja Trader


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one jdumanic with 5 posts (1 thanks)
    2. looks_two Fat Tails with 3 posts (2 thanks)
    3. looks_3 LostTrader with 1 posts (2 thanks)
    4. looks_4 Big Mike with 1 posts (0 thanks)
      Best Posters
    1. looks_one LostTrader with 2 thanks per post
    2. looks_two vegasfoster with 2 thanks per post
    3. looks_3 Fat Tails with 0.7 thanks per post
    4. looks_4 jdumanic with 0.2 thanks per post
    1. trending_up 6,401 views
    2. thumb_up 7 thanks given
    3. group 4 followers
    1. forum 9 posts
    2. attach_file 5 attachments




 
Search this Thread

Multi Time Frames - Ninja Trader

  #1 (permalink)
jdumanic
Zagreb, Croatia
 
Posts: 5 since Jun 2011
Thanks Given: 3
Thanks Received: 2

I really have a hard time figuring out how to use Filters in my Strategy which have different time frames than my primary indicators.

For example, I want to trade using 5 min price bars indicators, but only during those days when 10 DAY moving average > 50 DAY moving average (Filter).

Hence, my trouble is setting up Filters using DayPeriods while other indicators should have MinutePeriods. Any ides?

Thanx

Jere

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Better Renko Gaps
The Elite Circle
Cheap historycal L1 data for stocks
Stocks and ETFs
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #2 (permalink)
 vegasfoster 
las vegas
 
Experience: Intermediate
Platform: Sierra Chart
Broker: Velocity/IB
Trading: 6E
Posts: 1,145 since Feb 2010
Thanks Given: 304
Thanks Received: 844

Taken from the ninjatrader help file for the add() function.

 
Code
protected override void Initialize()
{
    // Add a 5 minute Bars object - BarsInProgress index = 1 
    Add(PeriodType.Minute, 5);
 
    // Add a 100 tick Bars object for the ES 12-06 contract - BarsInProgress index = 2 
    Add("ES 12-06", PeriodType.Tick, 100); 
} 
 
protected override void OnBarUpdate() 
{ 
    // Ignore bar update events for the supplementary Bars object added above 
    if (BarsInProgress == 1 || BarsInProgress == 2)
        return; 
 
    // Go long if we have three up bars on all bars objects 
    if (Close[0] > Open[0] && Closes[1][0] > Opens[1][0] && Closes[2][0] > Opens[2][0]) 
         EnterLong();
}

Reply With Quote
Thanked by:
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,460 since Jun 2009
Thanks Given: 33,234
Thanks Received: 101,655



jdumanic View Post
I really have a hard time figuring out how to use Filters in my Strategy which have different time frames than my primary indicators.

For example, I want to trade using 5 min price bars indicators, but only during those days when 10 DAY moving average > 50 DAY moving average (Filter).

Hence, my trouble is setting up Filters using DayPeriods while other indicators should have MinutePeriods. Any ides?

Thanx

Jere



Have you looked at the other examples found by using the search feature?


How to search:


Post your code so we can see how far you are and where you are stuck.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


jdumanic View Post
I really have a hard time figuring out how to use Filters in my Strategy which have different time frames than my primary indicators.

For example, I want to trade using 5 min price bars indicators, but only during those days when 10 DAY moving average > 50 DAY moving average (Filter).

Hence, my trouble is setting up Filters using DayPeriods while other indicators should have MinutePeriods. Any ides?

Thanx

Jere

The use of daily price bars in parallel with intraday price bars in NinjaTrader is probelmatic. Let me give an example first:


Example 1: segmented session


Chart 1 shows a multi bar series chart of YM 06-11. The session template divides the day into 2 subsessions, the night session and the day session. The daily data comes from Kinetick EOD.

Problem here is that the daily bars are time-stamped at 15:30 CET (Central European Time). This is the start of the RTH session. The correct time-stamp would be 22:15 CET. As you can see from the indicator that I added on the chart, it does not display the daily close (settlement) of the pior day correctly.


Example 2: non-segmented session

Chart 2 uses a non-segmented session template, which means one session per trading day. As you can see the time-stamp of the daily bars are correct and the daily data is added correctly.


Conclusion

If you want to add daily data to an intraday data bar series you should pay attention that the session template under instrument settings is non-segmented, otherwise NinjaTrader will not add daily data properly.

Have you considered the option to add minute bars with a bar period of 1440 minutes? You would be on the safe side.

I have added the indicator below, which you can use to test the behavior on NinjaTrader.

Attached Thumbnails
Click image for larger version

Name:	YM Segmented Session.jpg
Views:	300
Size:	109.5 KB
ID:	40563   Click image for larger version

Name:	YM Non-segemented Session.jpg
Views:	276
Size:	94.8 KB
ID:	40564  
Attached Files
Elite Membership required to download: PriorDaySettlementSync.zip
Reply With Quote
Thanked by:
  #5 (permalink)
jdumanic
Zagreb, Croatia
 
Posts: 5 since Jun 2011
Thanks Given: 3
Thanks Received: 2

@Fat Tails

Thanx for the effort. However, my problem is not displaying data on the chart ... it's rather about computing data using different Time Values and using it as a Filter. For example, if I set a Filter to trade only during those days when Price (5 min) > SMA10 (days) > SMA50 (days), than I need to access the value of 3 variables (Price is minute based, while SMA is based on daily closing prices). Unfortunately, after reading all related materials on this Board, I still don't know how to do it.


It would be a lot easier if Ninja Trader guys would just insert the „Time Value“ field within each Parameter, so you can choose individual values for each indicator, instead of having only one „Period Value“ for all Parameters.


Cheers.

Reply With Quote
Thanked by:
  #6 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


jdumanic View Post
@ Fat Tails

Thanx for the effort. However, my problem is not displaying data on the chart ... it's rather about computing data using different Time Values and using it as a Filter. For example, if I set a Filter to trade only during those days when Price (5 min) > SMA10 (days) > SMA50 (days), than I need to access the value of 3 variables (Price is minute based, while SMA is based on daily closing prices). Unfortunately, after reading all related materials on this Board, I still don't know how to do it.


It would be a lot easier if Ninja Trader guys would just insert the „Time Value“ field within each Parameter, so you can choose individual values for each indicator, instead of having only one „Period Value“ for all Parameters.


Cheers.

Whether you use an indicator on a chart or use a strategy without a chart, the instrument will use its underlying session template. I only wanted to show that there is a NinjaTrader bug, which prevents the use of daily bars and intraday bars, if you use a segmented session template. Just used the chart, because it explains the problem better than lots of data extracted from a strategy.

In case that you use a simple session template there is no problem and it is feasible.

If you describe a simple strategy, I can have a look at it.

Reply With Quote
  #7 (permalink)
jdumanic
Zagreb, Croatia
 
Posts: 5 since Jun 2011
Thanks Given: 3
Thanks Received: 2


vegasfoster View Post
Taken from the ninjatrader help file for the add() function.

 
Code
protected override void Initialize()
{
    // Add a 5 minute Bars object - BarsInProgress index = 1 
    Add(PeriodType.Minute, 5);
 
    // Add a 100 tick Bars object for the ES 12-06 contract - BarsInProgress index = 2 
    Add("ES 12-06", PeriodType.Tick, 100); 
} 
 
protected override void OnBarUpdate() 
{ 
    // Ignore bar update events for the supplementary Bars object added above 
    if (BarsInProgress == 1 || BarsInProgress == 2)
        return; 
 
    // Go long if we have three up bars on all bars objects 
    if (Close[0] > Open[0] && Closes[1][0] > Opens[1][0] && Closes[2][0] > Opens[2][0]) 
         EnterLong();
}

Thanx for the info.

Btw, when I do all this the Ninja Script sends an "error" message, so most likely I'm doing something wrong. Programming in C.# is really difficult (and frustrating) for someone w/o any programming experience (:

Reply With Quote
  #8 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


jdumanic View Post
Thanx for the info.

Btw, when I do all this the Ninja Script sends an "error" message, so most likely I'm doing something wrong. Programming in C.# is really difficult (and frustrating) for someone w/o any programming experience (:

It is a long way to go, I am not a programmer either. Best you buy a book with the basic stuff (250 pages), work through it, install the free Microsoft Visual C# Express Edition and go through all the exercises in this book. Once you have done that, progress will be fast, you just need to look how others are coding indicators and strategies and copy and paste. After some time the copy and paste approach will automatically vanish and be replaced with your own ideas and coding style.

Reply With Quote
  #9 (permalink)
 
LostTrader's Avatar
 LostTrader 
Tucson, AZ
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Mirus/Zen-Fire
Trading: CL, TF
Posts: 74 since Sep 2009
Thanks Given: 21
Thanks Received: 64


jdumanic View Post
For example, I want to trade using 5 min price bars indicators, but only during those days when 10 DAY moving average > 50 DAY moving average (Filter).

If the second post did not answer your question, then try studying this indicator code. All it does is add a second bar series, use that second series as the input to two SMA functions and save the comparison result, which is available as an external variable.

You can apply the same principle in your strategy code.

Bear in mind that this does not address the concern that Fat Tails raised: regardless of where you use the data (chart or strategy code) if you are not careful with your session template, the data will be wrong.

Attached Files
Elite Membership required to download: jereFilter.zip
Reply With Quote
Thanked by:
  #10 (permalink)
jdumanic
Zagreb, Croatia
 
Posts: 5 since Jun 2011
Thanks Given: 3
Thanks Received: 2



LostTrader View Post
If the second post did not answer your question, then try studying this indicator code. All it does is add a second bar series, use that second series as the input to two SMA functions and save the comparison result, which is available as an external variable.

You can apply the same principle in your strategy code.

Bear in mind that this does not address the concern that Fat Tails raised: regardless of where you use the data (chart or strategy code) if you are not careful with your session template, the data will be wrong.


This helps a lot. I understand the script logic much better now. Big thanx

Reply With Quote




Last Updated on June 17, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts