I have little experience with Python, so please bear with me.
I am trying to find the range (High-Low) for the last several days, and then calculate the average of those values. This was easy in a spreadsheet, but I am struggling to work with the arrays in Python.
I am starting with
H_History = history(context.days, "1d", "high")
L_History = history(context.days, "1d", "low")
I can't use the average of H_History & L_History separately. I need the average of the combination (H_History - L_History) from each day. I found
[Calculate the past 5 days' returns for each security.]
returns = (prices.iloc[-1] - prices.iloc[0]) / prices.iloc[0]
in the sample "Mean Reversion Algorithm", so it seems that something like
Range_History = H_History.iloc[0] - L_History.iloc[0]
should work, but I can't seem to get it to go. Ultimately I just want a number that I can pass to other calculations.