def ADX(df, n):
return pd.Series(talib.ADX(df['high'].values, df['low'].values, df['close'].values, timeperiod = n), index = df.index, name = 'ADX_%s' % str(n))
# UpMove = df['high'] - df['high'].shift(1)
# DoMove = df['low'].shift(1) - df['low']
# UpD = pd.Series(UpMove)
# DoD = pd.Series(DoMove)
# UpD[(UpMove<=DoMove)|(UpMove <= 0)] = 0
# DoD[(DoMove<=UpMove)|(DoMove <= 0)] = 0
# ATRs = ATR(df,span = n, min_periods = n)
# PosDI = pd.Series(pd.ewma(UpD, span = n, min_periods = n - 1) / ATRs)
# NegDI = pd.Series(pd.ewma(DoD, span = n, min_periods = n - 1) / ATRs)
# ADX = pd.Series(pd.ewma(abs(PosDI - NegDI) / (PosDI + NegDI), span = n_ADX, min_periods = n_ADX - 1), name = 'ADX' + str(n) + '_' + str(n_ADX))
# return ADX
评论列表
文章目录