Hi, I'm trying to calculate the average price of ohlc. I know that I can get these prices with data.history, but I'm new in Python, so I'm having troubles finding out how to make the calculation. I tried to apply the loop, but I'm getting errors. I bet there is a simple way of doing it which eludes me. I need to have the same type of pandas DataFrame as the standard 'close' prices as below, but instead of 'close' I need to have open + high + low + close / 4.
I tried to apply the loop below, but something's wrong with it.
context.bar_count = 10
price_history_ohlc = data.history(
context.security,
fields=['open', 'high', 'low', 'close'],
bar_count=context.bar_count,
frequency='1d')
for i in range(context.bar_count):
price_history_ohlc['ohlc_ave'] = (price_history_ohlc[['open']].iloc[i].values + price_history_ohlc[['close']].iloc[i].values + price_history_ohlc[['high']].iloc[i].values + price_history_ohlc[['low']].iloc[i].values )
The main necessity for this is to swap the 'close' price that I use in my implementation of the Hull Moving Average for the average of ohlc values, as the HMA based on 'close' behaves rather awfully. I'm surprised with such a poor results, so I want to improve them.
If anyone has any suggestion on the implementation of the ohlc average DataFrame or on different strategy using HMA, please let me know.
Thanks and regards.