Announcement
Collapse
No announcement yet.
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.
-
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; } }You can use the following reference sample for adding user defined input parameters to your NinjaScript: http://ninjatrader.com/support/forum...ead.php?t=5782Code: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.
Comment
-
Thank you,
I ended up approaching it like this:

I still would prefer to be able to default the values of the secondary series to match the Input series. However, it appears the indicator does not have access to that information even though it is accessible from the Indicator Properties dialog.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:

I.e. the Input series type and period are inherited.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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
649 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 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
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
576 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|
Comment