On the reading of the first bar of the data series, the variable named "divisor" will be set to 0, and the calculation of the variable named "slope" will result in a NaN value. The values of intercept and linReg rely on slope, therefore their values are also NaN.
This only seems to occur on the first bar, but I was using the calculated value of linReg to set the value of my custom series, and then passing that custom series to the SMA method, and that is how I discovered the Nan bug.
Consider testing the value of divisor inside the IsFirstTickOfBar conditional.
psuedocode
if (divisor != 0 ) { Print("divisor is not 0"); } else { Print("divisor IS 0, so we set it to 1 "); divisor = 1; }
Comment