DMI算法有误,贡献一个更正后的算法
WangXiaopai595 opened this issue · comments
王小牌 commented
通过和币安、欧易对比,DMI值相差非常大,应该是算法有误
王小牌 commented
经过对算法分析,你这个算法部分地方有bug,正确代码如下:
def DMI(CLOSE, HIGH, LOW, M1=14, M2=6):
TR = SMA(MAX(MAX(HIGH - LOW, ABS(HIGH - REF(CLOSE, 1))), ABS(LOW - REF(CLOSE, 1))), M2)
UP = HIGH - REF(HIGH, 1)
DOWN = REF(LOW, 1) - LOW
DMP = SMA(IF((UP > 0) & (UP > DOWN), UP, 0), M2)
DMM = SMA(IF((DOWN > 0) & (DOWN > UP), DOWN, 0), M2)
PDI = DMP * 100 / TR
MDI = DMM * 100 / TR
ADX = SMA(ABS(MDI - PDI) / (PDI + MDI) * 100, M1)
ADXR = (ADX + REF(ADX, M1)) / 2
return PDI, MDI, ADX, ADXR