Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy based on multi-time frames
Collapse
X
-
Strategy based on multi-time frames
I am new to Ninjatrader. How can I define following: IF On daily time-frame SMA(5) crosses above SMA(8) and SMA(13) and ParabolicSAR(0.02, 0.2, 0.02) is under the price AND on weekly time-frame (the previous week) SMA(5) is under SMA(8) and SMA(13) and ParabolicSAR(0.02, 0.2, 0.02) is under the price THEN enter long. Thanks.Tags: None
-
Thank you for contacting us regarding your inquiry.
First initialize the 2 times frames as follows in Initialize():
Add(PeriodType.Day, 1); // =BarsArray[0]
Add(PeriodType.Week, 1); // = BarsArray[1]
This can be done by inserting this code into your OnBarUpdate() :
if (BarsInProgress != 0)
return;
if(CrossAbove(SMA(Closes[1],5) ,SMA(Closes[1],8), 1)
&& CrossAbove(SMA(Closes[1],5), SMA(Closes[1],13), 1)
&& SMA(Closes[2],5)[0]< SMA(Closes[2],8)[0]
&& SMA(Closes[2],5)[0]< SMA(Closes[2],13)[0]
&& ParabolicSAR(Closes[1],0.02,0.2,0.02)[0] < Close[0]
&& ParabolicSAR(Closes[2],0.02,0.2,0.02)[0] < Close[0])
EnterLong();
(***Please note I had to use a look back value (the final 1 in the code below) with the cross over check. In this case, I used 1 day lookback for the cross over to occur. This can be changed to if you want to incorporate recent days for the cross to occur.
SMA(Closes[1],8), 1) )
Here is a link for your reviewhttp://ninjatrader.com/support/helpGuides/nt7/crossabove.htm
Matt L.NinjaTrader Customer Service
-
Thank you very much for help, it seems to work but still need small improvement, i put my comments in italics.
First initialize the 2 times frames as follows in Initialize():
Add(PeriodType.Day, 1); // =BarsArray[0]
Add(PeriodType.Week, 1); // = BarsArray[1]
This can be done by inserting this code into your OnBarUpdate() :
if (BarsInProgress != 0)
return;
if(CrossAbove(SMA(Closes[1],5) ,SMA(Closes[1],8), 1)
&& CrossAbove(SMA(Closes[1],5), SMA(Closes[1],13), 1)
//are these crosses on daily frames?
&& SMA(Closes[2],5)[0]< SMA(Closes[2],8)[0]
&& SMA(Closes[2],5)[0]< SMA(Closes[2],13)[0]
//are these on conditions on weekly?
&& ParabolicSAR(Closes[1],0.02,0.2,0.02)[0] < Close[0]
//is this on daily?
&& ParabolicSAR(Closes[2],0.02,0.2,0.02)[0] < Close[0])
//is this weekly on previous week?
//according to results it seems it is looking at the week of the day, not on the previous week (preceding the day on which crosses happened)
EnterLong();
Comment
-
Jirkos,
The [1] after Close represents which data series is being reference. So in this case:
if(CrossAbove(SMA(Closes[1],5) ,SMA(Closes[1],8), 1)
&& CrossAbove(SMA(Closes[1],5), SMA(Closes[1],13), 1)
&& ParabolicSAR(Closes[1],0.02,0.2,0.02)[0] < Close[0]
All of the above deal with daily data [1]. anything with a [2] represents the second data series which we declared up top.
To answer your second question, referencing the previous week would change the code to:
&& SMA(Closes[2],5)[1]< SMA(Closes[2],8)[1]
&& SMA(Closes[2],5)[1]< SMA(Closes[2],13)[1]
&& ParabolicSAR(Closes[2],0.02,0.2,0.02)[1] < Close[0])
Also, please replace "if (BarsInProgress != 0)"
to if(CurrentBars[1] >0) . This is a better check than the original one I provided.Matt L.NinjaTrader Customer Service
Comment
-
[QUOTE=NinjaTrader_MattL;426696]Thank you for contacting us regarding your inquiry.
First initialize the 2 times frames as follows in Initialize():
Add(PeriodType.Day, 1); // =BarsArray[0]
Add(PeriodType.Week, 1); // = BarsArray[1]
When setting up a chart, one can select minutes and even seconds. Can these periods be used here and if using seconds, how much processor load will that cause? Thanks in advance.
Comment
-
Dolfan,
Thank you for your inquiry. Yes, both minutes and seconds can be added, in the similar syntax as the others. Here is a link that describes this, and also how bars are formed.
Using additional data series and timeframes can put an additional load on the processor, but it is hard to determine as that can be strategy and computer specific.
Let us know if we can help any further.Matt L.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
633 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment