protectedoverridevoidOnStateChange()
{
if (State == State.SetDefaults)
{
.....
BarsRequiredToTrade = 5;
......
}
protectedoverridevoidOnBarUpdate()
{
if (Bars.IsFirstBarOfSession)
{
if (Open[0] >= (Close[1]+GapSize))
{
TradeCount = TradeCount+1;
}
}
And I get the following error message:
Error on calling 'OnBarUpdate' method on bar 0: 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.
Why is the BarsRequiredToTrade not preventing this error? What code do I need to avoid this?
Comment