My strategy uses multitimeframe bars. All the BarsArray access are done with BarsArray[BarsInProgress], the same applies to accessing Closes, Highs etc.
It is running fine normally, but it would get the Index was out of range error when bars are appearing ultra-fast like sometimes happens on CL. This usually more than 10 bars appearing in a second.
The first thing my OnBarUpdate does is to print
if (debug >= dbgBip)
Print(Time.ToString() + " " + Instrument.FullName + " <<<>>> BAR STARTS: BIP " + BarsInProgress + " CBar: " + CurrentBar + " CLOSE: " + Closes[BarsInProgress][0]);
if (debug >= dbgBip)
Print(Time.ToString() + " " + Instrument.FullName + " " + BarsArray[BarsInProgress].Period.ToString() + " BAR STARTS: BIP " + BarsInProgress + " CBar: " + CurrentBar + " CLOSE: " + Closes[BarsInProgress][0]);
After running, I found exactly the CurrentBar values when it crashes, then I add after the above codes:
if (BarsInProgress == 0 && CurrentBar >= dbgBar0) {
Print(Time.ToString() + " " + Instrument.FullName + " " + BarsArray[BarsInProgress].Period.ToString() + " OnBarUpdate0 BIP " + BarsInProgress + " CBar: " + CurrentBar + " CLOSE: " + Closes[BarsInProgress][0]);
return;
}
if (BarsInProgress == 0 && CurrentBar >= dbgBar1) {
Print(Time.ToString() + " " + Instrument.FullName + " " + BarsArray[BarsInProgress].Period.ToString() + " OnBarUpdate1 BIP " + BarsInProgress + " CBar: " + CurrentBar + " CLOSE: " + Closes[BarsInProgress][0]);
return;
}
dbgBar0 and dbgBar1 is set at initialize to appropriate values, after finding out value of CurrentBar just before the error during previous market replay run. Note that I run at 1X near the error time.
Just before error happens appropriate prints came out.
Now when the error happens, none of the above prints! This seems to suggest something else has gone wrong but likely not inside my code. Also I do not have parameter named Index or index.
What is going on here ? And how can I solve this issue?
Thanks.
Regards,
EdwardK.

Comment