I am trying to use the Swing method or the Most Recent Occurrence (MRO) method to give a signal when one of my plots achieves a higher high, but I am getting the following error:
"Error on calling 'OnBarUpdate' method on bar 21: 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 have read the threads about this, and my indicator is not multiseries, and I have used
if (CurrentBars[0] <= BarsRequiredToPlot)
{ return;}
//Method A
int barsAgoSHH1 = Swing(Values[0], 1).SwingHighBar(0, 3, 14);
int barsAgoSHH0 = Swing(Values[0], 1).SwingHighBar(0, 4, 14);
if(Values[0][barsAgoSHH1] > Values[0][barsAgoSHH0])
{
Draw.RegionHighlightX(this, "tagbullrise" + CurrentBar, 6, 0, Brushes.Transparent, Brushes.Green, 25);
}
//Method B
int barsAgoHH1 = MRO(() => Values[0][0] > Values[0][1], 3, 12);
int barsAgoHH0 = MRO(() => Values[0][0] > Values[0][1], 4, 12);
if(Values[0][barsAgoHH1] > Values[0][barsAgoHH0])
{
Draw.RegionHighlightX(this, "tagbullrise" + CurrentBar, 6, 0, Brushes.Transparent, Brushes.Green, 25);
}

Comment