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
Accessing values of multiple manually added Data Series
Collapse
X
-
Hello drmartell,
Thanks for writing in.
NinjaScripts have no way of knowing how many data series have been added to a chart when that indicator is applied to that chart. You can manually set the indicator to point to the other data series, but the NinjaScript cannot know this on its own.
If you would like to use multiple data series for calculations in an indicator, you will have to add the data series from code.
You can use AddDataSeries() to accomplish this.
There is a sample strategy on our forums that outlines how to use multiple data series which may be of use to you:
You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by
I will also copy links to the relevant documentation it uses.
Please also take the time to read the documentation on creating NinjaScripts for Multi-Time Frame & Instruments: http://ninjatrader.com/support/helpG...nstruments.htm
If you have any additional questions please don't hesitate to ask.JimNinjaTrader Customer Service
-
If your adding a second or third data series to a chart you can add the same data series for calculation purposes inside the indicator as Ninja_Jim indicated. If you only need them on the chart for calculation purposes inside your indicator, you don't need to add them to the chart only in the indicator.
Comment
-
Hello drmartell,
As DataSeries are added in State.Configure, this is not advised. You can, however, add all of the data series you need and you can add parameters that disable processes for certain overloads by adding a return condition for the data series you do not want to use.
For example, for every additional data series that you add in State.Configure, you can use a bool to tell if that instrument is listed as a parameter. Please consider a private bool UseAdditionalESDataSeries in the example below.
Code:protected override void OnStateChange() { if (State == State.SetDefaults) { ... Instrument1 = @"ES 06-17"; } else if (State == State.Configure) { AddDataSeries("ES 06-17", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last); } else if (State == State.DataLoaded) { if( Instrument1 != "ES 06-17") UseAdditionalESDataSeries = false; } }
Code:protected override void OnBarUpdate() { if ((UseAdditionalESDataSeries == false) && (BarsInProgress == 1)) return; //Add your custom strategy logic here. }
Please let me know if you have any additional questions.JimNinjaTrader Customer Service
Comment
-
Thank you,
I ended up approaching it like this:
Code:else if (State == State.Configure) { try { AddDataSeries(SecondaryInstrument, MyBarsPeriodType, MyBarsPeriodValue); } catch { System.Windows.Forms.MessageBox.Show("Unable to load secondary Data Series"); } } else if (State == State.DataLoaded) { if (MyBarsPeriodType != BarsPeriod.BarsPeriodType || MyBarsPeriodValue != BarsPeriod.Value) System.Windows.Forms.MessageBox.Show("Secondary Data Series type and period must match Primary Series"); }
Comment
-
Ok actually, this is closer to what I wanted and is working:
Code:else if (State == State.Configure) { try { AddDataSeries(SecondaryInstrument, Bars.BarsPeriod.BarsPeriodType, Bars.BarsPeriod.Value); } catch { System.Windows.Forms.MessageBox.Show("Unable to load secondary Data Series"); } }
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Tburg1073, Today, 08:36 AM
|
0 responses
2 views
0 likes
|
Last Post
by Tburg1073
Today, 08:36 AM
|
||
Started by alexstox, 10-16-2018, 03:29 PM
|
10 responses
333 views
0 likes
|
Last Post
by Tburg1073
Today, 08:32 AM
|
||
Started by smartromain, 03-13-2024, 01:42 AM
|
6 responses
98 views
0 likes
|
Last Post
by smartromain
Today, 08:30 AM
|
||
Started by Jonker, 04-27-2024, 01:19 PM
|
4 responses
29 views
0 likes
|
Last Post
by Jonker
Today, 08:26 AM
|
||
Started by Yasharandom, Today, 07:45 AM
|
0 responses
5 views
0 likes
|
Last Post
by Yasharandom
Today, 07:45 AM
|
Comment