DMI策略

2021-12-3 / 0 评论 / 1213 阅读
温馨提示:
本文最后更新于2021-12-3,已超过半年没有更新,若内容或图片失效,请留言反馈。

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

评论一下?

OωO
取消