I was defining a function Heiken Ashi which is one of the popular chart type in Technical Analysis. I was writing a function on it using Pandas but finding little difficulty. T
I adjusted the code to make it work with Python 3.7
def HA(df):
df_HA = df
df_HA['Close']=(df['Open']+ df['High']+ df['Low']+df['Close'])/4
#idx = df_HA.index.name
#df_HA.reset_index(inplace=True)
for i in range(0, len(df)):
if i == 0:
df_HA['Open'][i]= ( (df['Open'][i] + df['Close'][i] )/ 2)
else:
df_HA['Open'][i] = ( (df['Open'][i-1] + df['Close'][i-1] )/ 2)
#if idx:
#df_HA.set_index(idx, inplace=True)
df_HA['High']=df[['Open','Close','High']].max(axis=1)
df_HA['Low']=df[['Open','Close','Low']].min(axis=1)
return df_HA