其他分享
首页 > 其他分享> > DMI策略

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年:

图片alt

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

 

标签:ma,策略,df,DMI,len,dmi,seting
来源: https://blog.csdn.net/sumubaiblog/article/details/121714248