I'm receving the 2 errors below on an indicator that I've created:
Indicator 'CongestionBoxLite': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.
Indicator 'DynamicSRCongestionBoxLite': 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.
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 1)
return;
if (Bars.IsFirstBarOfSession)
{
SRLine[0] = Open[0];
}
else if (Close[0] > CongestionBoxLite1.UpperBoundarySeries[0])
{
SRLine[0] = CongestionBoxLite1.LowerBoundarySeries[0];
}
else if (Close[0] < CongestionBoxLite1.LowerBoundarySeries[0])
{
SRLine[0] = CongestionBoxLite1.UpperBoundarySeries[0];
}
else if (CurrentBar>0 && SRLine.IsValidDataPointAt(CurrentBar-1))
{
SRLine[0] = SRLine[1];
}

Comment