BOLL布林带定向策略

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

1. 策略原理

当收盘价上穿下轨,做多
当收盘价下穿上轨,做空
图片alt

代码:

seting = {'name': 'BBv3', 'symbol': 'BTCUSDT', 'kTime': '15m', 'bb_len': 7, 'buy_len': 44, 'buy_mult': 2.664, 'sell_len': 20, 'sell_mult': 2.54, 'buy': 1, 'buyZhiying': 12.704, 'buyZhisun': 7.525, 'sell': 1, 'sellZhiying': 6.112, 'sellZhisun': 1.52}

"""
布林带升级版定向策略
"""
def BBv3(r, df, seting):
    df['ma'] = SMA(r, seting['bb_len'], 'Close')

    df['upper'] = df['ma'] + seting['sell_mult'] * talib.STDDEV(df['Close'], timeperiod=seting['sell_len'])
    df['lower'] = df['ma'] - seting['buy_mult'] * talib.STDDEV(df['Close'], timeperiod=seting['buy_len'])

    c = len(df)
    for i in range(c):
        if i > seting['sell_len'] and i+1 < c:
            if df['Close'][i] > df['lower'][i] and df['Close'][i-1] < df['lower'][i-1]: # and df['Close'][i] > df['ma2'][i]
                df['side'].values[i] = 'BUY'

            if df['Close'][i] < df['upper'][i] and df['Close'][i-1] > df['upper'][i-1]: # and df['Close'][i] < df['ma2'][i]
                df['side'].values[i] = 'SELL'

    return df

2.回测结果

BTCUSDT 15m:
图片alt

评论一下?

OωO
取消