Thanks in advance for you help.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Multiple Data Series.
Collapse
X
-
Multiple Data Series.
I was hoping that someone could help me as I am trying to learn NinjaScript. Is is possible to code an sma 8 period with a chart on a 15 minute time frame then code a second sma 8 period pulling data from a daily chart or another minute time frame like a 240 minute time frame?
Thanks in advance for you help.Tags: None
-
Hello,
Thanks for your post.
This is certainly possible. When you apply your strategy to a chart, the data series in that chart will be the primary data series of the strategy. You would add whatever data series you wanted to State.Configure, in this case your 1 day series and your 240 minute series. Next, you would add your SMA's in OnBarUpdate using Closes[][] as the input. Closes is used whenever you need to access closing prices for multiple instruments or multiple time frames.
I have created an example of doing this is the code snippet below.
protected override void OnStateChange(){
else if (State == State.Configure){
AddDataSeries(Data.BarsPeriodType.Day, 1);
AddDataSeries(Data.BarsPeriodType.Minute, 240);
}
}
protected override void OnBarUpdate(){
double mySMA0 = SMA(Closes[0][0],13);
double mySMA1 = SMA(Closes[1][0],13);
double mySMA2 = SMA(Closes[2][0],13);
}
There is a great strategy reference sample built into NT8 called SampleMACrossover that I recommend checking out as well. You may find this sample in the Strategies folder inside of the NinjaScript editor.
I am also including a link below to our help guide documentation on Multiple Times Frames and Instruments, SMA, and Closes, for your convenience.
SMA
https://ninjatrader.com/support/help...simple_sma.htm
Closes
https://ninjatrader.com/support/help...us/?closes.htm
Multi-Time Frame & Instruments
https://ninjatrader.com/support/help...nstruments.htm
Please let me know if you have any further questions.Last edited by NinjaTrader_JoshG; 10-26-2017, 03:42 PM.Josh G.NinjaTrader Customer Service
-
Hello,
This code would work for an indicator or a strategy. Have you added the plots that you wanted to your code, using AddPlot() ?
AddPlot()
https://ninjatrader.com/support/help...s/?addplot.htm
You can always open up one of the pre-existing indicators you like as well to see how this is done.
Please let me know if you have any further questions.Josh G.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
576 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment