I have a for loop below to calculate heiken shi inside bars. It works for a few bars then gives the common error on bar 50. I am not sure why on bar 50 it can't compute anymore?
The common check of BarsRequired did not work. What would make it work under these conditions?
Error on calling 'OnBarUpdate' method for indicator 'itTestCode' on bar 50: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
if (CurrentBar < BarsRequired)
return;
#region Inside Bars
double currentBarRealBody = Math.Abs(HeikenAshi().HAClose[0] - HeikenAshi().HAOpen[0]);
for (int i = 0; currentBarRealBody < Math.Abs(HeikenAshi().HAClose[i+1] - HeikenAshi().HAOpen[i+1]); i++)
{
if (i >= 3) // if there is 3 inside bars
{
DrawArrowUp("MyArrowUp2"+CurrentBar, 0, Low[0], Color.Black);
}
}
Comment