I'm writing an average true range function as a custom factor for the pipeline. The true range of a day is the highest value between the ranges of today's high and low, and yesterday's close and today's high and low. The average true range is the average of all the day's true range within the window length. In the code, I loop the true range calculation with "i" counting the amount of times the loop has run. I define "i" as 0 before the loop but when I debug, I get an error [The truth value of an array with more than one element is ambiguous. Use a.any() or a.all())] when I say i = i + 1. I don't believe I have redefined i as an array anywhere in my code. Perhaps there is something I am overlooking?
class ATR(CustomFactor):
def compute(self, today, asset_ids, out, close, high, low):
window_length = 20
hl = []
hc = []
lc = []
tr = []
i = 0
while i < window_length:
hl.append(high[-i] - low [-i])
hc.append(high[-i] - close[-i - 1])
lc.append(low[-i] - close[-i - 1])
tr.append(max(hl[i], hc[i], lc[i]))
i = i + 1
ATR = mean.tr
out[:] = ATR