This might be the same problem. Print the output of your series at any bar for checking. Especially at the begin at bar 0, when prices are not yet loaded and indicators are 0, subtracting two values can cause a division by zero.