Consider the following code.
class SomeIndicator: Indicator { protected override void OnStateChange() { switch(State) { case State.SetDefaults: //... break; case State.Configure: { var barsPeriod = new BarsPeriod() { BarsPeriodType = BarsPeriodType.Day, Value = 1, MarketDataType = MarketDataType.Last }; AddDataSeries(Instrument.FullName, barsPeriod, 30, Instrument.MasterInstrument.TradingHours.Name, null); sma = SMA(BarsArray[1], 14); } break; } } protected override void OnBarUpdate() { if(BarsInProgress == 0) { Print("Bar " + CurrentBars[0]); if(CurrentBars[1] > sma.Period) { for(int i = 0; i < CurrentBars[1]; i++) { // Cannot execute this code because despite CurrentBars[1] being 27, sma[0] is not valid (let alone any additional values) //Print("SMA " + sma[i]); } } } else if(BarsInProgress == 1) { Print("Daily Bar " + CurrentBars[1]); } } SMA sma; }
How do I get sma to be populated with the 27 days of data that its data series has?
Comment