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 judysamnt7, 03-13-2023, 09:11 AM
|
4 responses
53 views
0 likes
|
Last Post
by DynamicTest
Today, 08:25 PM
|
||
Started by ScottWalsh, Today, 06:52 PM
|
4 responses
33 views
0 likes
|
Last Post
by ScottWalsh
Today, 07:40 PM
|
||
Started by olisav57, Today, 07:39 PM
|
0 responses
5 views
0 likes
|
Last Post
by olisav57
Today, 07:39 PM
|
||
Started by trilliantrader, Today, 03:01 PM
|
2 responses
19 views
0 likes
|
Last Post
by helpwanted
Today, 07:25 PM
|
||
Started by cre8able, Today, 07:24 PM
|
0 responses
6 views
0 likes
|
Last Post
by cre8able
Today, 07:24 PM
|
Comment