I have been getting this error:
"Error on calling 'OnBarUpdate' method on bar -1: 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."
I've seen this in the past a few times and not really understood what was happening.
But first... Error checking code like this seems to be pretty standard in strategy templates at the top of OnBarUpdate():
if (CurrentBars[0] < BarsRequiredToTrade)
{
Log("Number of bars (" + CurrentBars[0] + ") is less than BarsRequiredToTrade (" + BarsRequiredToTrade + "); Returning");
return;
}
My strategy uses BiP = 0 & 1 (for tick data). So I have my code like this:
protected override void OnBarUpdate()
{
if (State != State.Historical)
{
if (CurrentBars[0] < BarsRequiredToTrade || CurrentBars[1] < BarsRequiredToTrade)
{
Log("STATE = " + State.ToString() + "; Number of bars (BiP[0] = " + CurrentBars[0] + " & BiP[1] = " + CurrentBars[1] +
") is less than BarsRequiredToTrade (" + BarsRequiredToTrade + "); Returning");
return;
}
}
else if (!PlotHist) // input to turn off historical processing to speed up init
return;
// rest of code...
}
Strategy 'FiftyLevel': Error on calling 'OnBarUpdate' method on bar -1: 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.
So it's not hitting the "BarsRequiredToTrade" check now; maybe the two are unrelated. But I'd like to get rid of that error, and I do not see any Log messages after the error.
Can you shed some light on this?

Comment