Heiken Ashi Using pandas python

前端 未结 7 2066
南方客
南方客 2021-01-31 23:23

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

相关标签:
7条回答
  • 2021-02-01 00:06

    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
    
    0 讨论(0)
提交回复
热议问题