int BarsAgo = Swing(SwingStrength).SwingHighBar(0, 1, Bars.BarsSinceNewTradingDay);
if(BarsAgo < 0 || CurrentBar <= BarsAgo) return;
double swingHigh = Swing(SwingStrength).SwingHigh[BarsAgo];
The strategy works properly for some date ranges. For some date ranges, It would pop up an error as follows
2024/10/24 15:16:26,Default,Strategy 'SwingTest': Error on calling 'OnBarUpdate' method on bar 34790: 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.,
My question is how to trap this error so the strategy could continue to run.

Comment