Thanks in advance for you help.
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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 Stanfillirenfro, Today, 07:23 AM
|
8 responses
23 views
0 likes
|
Last Post Today, 10:02 AM | ||
Started by DayTradingDEMON, Today, 09:28 AM
|
2 responses
15 views
0 likes
|
Last Post Today, 09:56 AM | ||
Started by navyguy06, Today, 09:28 AM
|
1 response
6 views
0 likes
|
Last Post Today, 09:54 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
8 responses
32 views
0 likes
|
Last Post Today, 09:34 AM | ||
Started by helpwanted, Today, 03:06 AM
|
2 responses
22 views
0 likes
|
Last Post Today, 09:30 AM |
Comment