The AddDataSeries api allows scripts to load supplemental dataseries. These are price data streams that are distinct and separate from the chart or “primary” dataseries that the indicator/strategy is running on. The OHLCV of these supplemental series can be referenced by specifying the barsarray index.
So if a script calls
AddDataSeries(“ES 09-21”);
By the way, as a side bar suggestion to this post it would be great if AddDataSeries returned the index of the bar series that is assigned to it.
The other data points of the OHLCV supplemental series can be accessed in similar fashion:
Opens[1][0], Highs[1][0], Lows[1][0], Volume[1][0].
Now suppose a strategy uses indicators internally and the strategy wants the indicators to use the supplemental series. No problem, the NinjaScript code generator that creates the constructor script for its hosted indicators creates an overload for each indicator so that the strategy can specify which dataseries the hosted indicator should use:
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.SMA SMA(int period) { return indicator.SMA(Input, period); } public Indicators.SMA SMA(ISeries<double> input , int period) { return indicator.SMA(input, period); } }
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.ADX ADX(int period) { return indicator.ADX(Input, period); }
SMA(Closes[1], 14);
SMA(Volumes[0], 14) or SMA(Volumes[1], 14) to get the average volume of NQ and ES.
Suppose the user wants the ADX of the supplemental dataseries:
public Indicators.ADX ADX(ISeries<double> input , int period) { return indicator.ADX(input, period); }
Continuing with our example, to get the ADX of ES :
ADX(Closes[1], 14);
There is a BarsInProgress property that indicates what the current bars in progress are in any given call to OnBarUpdate. If BarsInProgress is equal to 1 then a call to ADX(14) or ATR(14) returns the values for the BarsArray[1] ? If so is it valid to cache the references returned?
ADX adxForES; ATR adxForNQ; if(BarsInProgress == 0) adxForNQ = ADX(14); else if(BarsInProgress == 1) adxForES = ADX(14);
To use supplemental dataseries with hosted indicators, the hosting script MUST make sure that the hosted indicator is run in the context of the BIP that it's intended to run in. But how?
I see there's an overload to the Update method. How is this to be used?
public void Update(int idx, int bip);
adxForES.Update(0,1);
Comment