When I use "int" values for ema200SlopeA it works fine. But when I try to switch to Series<int> for ema200SlopeA, I get this error
"Indicator 'Stack': Error on calling 'OnBarUpdate' method on bar 300: Object reference not set to an instance of an object."
below is the code where I initialize and then calculate the values for ema200SlopeA. When I use just an "int" it works fine. When I switch to Series I get the error.
I have this statement in so that I don't get an out of range error " if (CurrentBar < 300) return; "
it seems simple, but I'm missing something
thanks
public class Stack : Indicator
{
private Series<int> ema200SlopeA;
private int ema50SlopeA;//, ema200SlopeA;
private int ema50SlopeB, ema200SlopeB;​
protected override void OnBarUpdate()
{
if(DateTime.Today > new DateTime(2023, 09, 01, 0, 0, 0)) return; // filter to stop running if old version
ema50A = EMA(BarsArray[1],50); // these are type EMA
ema50B = EMA(BarsArray[2],50);
ema200A = EMA(BarsArray[1],200);
ema200B = EMA(BarsArray[2],200);
if (CurrentBar < 300) return;
trendDirection = 0;
if(ema50A[0] > (ema50A[lookBack] + TickSize/s50))
ema50SlopeA = 1;
else if(ema50A[0] < (ema50A[lookBack] - TickSize/s50))
ema50SlopeA = -1;
else
ema50SlopeA = 0;
if(ema200A[0] > ema200A[lookBack] + TickSize/s200)
ema200SlopeA[0] = 1;
else if(ema200A[0] < ema200A[lookBack] - TickSize/200)
ema200SlopeA[0] = -1;
else
ema200SlopeA[0] = 0;
​

Comment