def HEIKEN_ASHI(df, period1):
SM_O = pd.rolling_mean(df['open'], period1)
SM_H = pd.rolling_mean(df['high'], period1)
SM_L = pd.rolling_mean(df['low'], period1)
SM_C = pd.rolling_mean(df['close'], period1)
HA_C = pd.Series((SM_O + SM_H + SM_L + SM_C)/4.0, name = 'HAclose')
HA_O = pd.Series(SM_O, name = 'HAopen')
HA_H = pd.Series(SM_H, name = 'HAhigh')
HA_L = pd.Series(SM_L, name = 'HAlow')
for idx, dateidx in enumerate(HA_C.index):
if idx >= (period1):
HA_O[idx] = (HA_O[idx-1] + HA_C[idx-1])/2.0
HA_H[idx] = max(SM_H[idx], HA_O[idx], HA_C[idx])
HA_L[idx] = min(SM_L[idx], HA_O[idx], HA_C[idx])
return pd.concat([HA_O, HA_H, HA_L, HA_C], join='outer', axis=1)
评论列表
文章目录