DMI策略

1.策略原理

很简单的一个策略,只用了DMI一个指标
获得DMI两条线后相减,再把值做平滑处理
值 > 0 且大于上一个值 就做多

DMI指标的计算可以看我发过的ADX指标里面有

代码:

"""
DMI指标策略
"""
def DMI(r, df, seting):
    a, b = DI(r, seting['dmi_len'])
    df['dmi'] = a-b
    
    if seting['ma_type'] == 'sma':
        df['dmi'] = SMA(df['dmi'].values, seting['ma_len'])

    if seting['ma_type'] == 'ema':
        df['dmi'] = talib.EMA(df['dmi'].values, seting['ma_len'])

    if seting['ma_type'] == 'rma':
        df['dmi'] = RMA(df['dmi'].values, seting['ma_len'])
        

    c = len(df)
    for i in range(c):
        if i > seting['ma_len'] and i+1 < c:
            if df['dmi'][i] > 0 and df['dmi'][i] > df['dmi'][i-1]:
                df['side'].values[i] = 'BUY'

            if df['dmi'][i] < 0 and df['dmi'][i] < df['dmi'][i-1]:
                df['side'].values[i] = 'SELL'

    return df

2.回测结果

15mk线 2021年:

DMI策略

原文地址: DMI策略 - 苏慕白的博客 

 

上一篇:pandas之面属行统计


下一篇:时间序列预测的7种Python工具包,总有一款适合你