Have a peculiar problem where the error message " Error on calling 'OnBarUpdate' method on bar 291: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart." keeps appearing despite the code looking fine.
Here's the State.Configure portion of the code:
else if (State == State.Configure) { AddDataSeries(Data.BarsPeriodType.Minute, 10); AddDataSeries(Data.BarsPeriodType.Minute, 15); AddDataSeries(Data.BarsPeriodType.Minute, 30); AddDataSeries(Data.BarsPeriodType.Minute, 60); M10Highs = Highs[1]; M10Lows = Lows[1]; M15Highs = Highs[2]; M15Lows = Lows[2]; M30Highs = Highs[3]; M30Lows = Lows[3]; H1Highs = Highs[4]; H1Lows = Lows[4]; }
Here's the OnBarUpdate portion of the code:
protected override void OnBarUpdate() { Print("On bar update method called"); if((CurrentBars[1] < NumberOfCandles) || (CurrentBars[2] < NumberOfCandles) || (CurrentBars[3] < NumberOfCandles) || (CurrentBars[4] < NumberOfCandles)) { Print("Insufficient candles"); return; } else { M10ValuesList = IndicatorToolBox.GetValues(M10Highs, M10Lows, NumberOfCandles, NumberOfValues); Print("M10 Values found"); M15ValuesList = IndicatorToolBox.GetValues(M15Highs, M15Lows, NumberOfCandles, NumberOfValues); Print("M15 Values found"); M30ValuesList = IndicatorToolBox.GetValues(M30Highs, M30Lows, NumberOfCandles, NumberOfValues); Print("M30 Values found"); H1ValuesList = IndicatorToolBox.GetValues(H1Highs, H1Lows, NumberOfCandles, NumberOfValues); Print("H1 Values found"); RemoveDrawObjects(); for(int i = 0; i < M10ValuesList.Count(); i++) { if(M10ValuesList[i] > M10Highs[0]) { Draw.HorizontalLine(this, ("M10 Values " + i), M10ValuesList[i], Brushes.Green); } else if(M10ValuesList[i] < M10Lows[0]) { Draw.HorizontalLine(this, ("M10 Values " + i), M10ValuesList[i], Brushes.Green); } } for(int i = 0; i < M15ValuesList.Count(); i++) { if(M15ValuesList[i] > M15Highs[0]) { Draw.HorizontalLine(this, ("M15 Values " + i), M15ValuesList[i], Brushes.Yellow); } else if(M15ValuesList[i] < M15Lows[0]) { Draw.HorizontalLine(this, ("M15 Values" + i), M15ValuesList[i], Brushes.Yellow); } } for(int i = 0; i < M30ValuesList.Count(); i++) { if(M30ValuesList[i] > M30Highs[0]) { Draw.HorizontalLine(this, ("M30 Values " + i), M30ValuesList[i], Brushes.Orange); } else if(M30ValuesList[i] < M30Lows[0]) { Draw.HorizontalLine(this, ("M30 Values " + i), M30ValuesList[i], Brushes.Orange); } } /* for(int i = 0; i < H1ValuesList.Count(); i++) { if(H1ValuesList[i] > H1Highs[0]) { Draw.HorizontalLine(this, ("H1 Values " + i), H1ValuesList[i], Brushes.Red); } else if(M10ValuesList[i] < H1Lows[0]) { Draw.HorizontalLine(this, ("H1 Values " + i), H1ValuesList[i], Brushes.Red); } }*/ } } }
Thanks and Regards,
Somebody
Comment