Boll布林带突破策略
温馨提示:本文最后更新于2021年12月4日 10:58,若内容或图片失效,请在下方留言或联系博主。
1.策略原理
一个很简单的策略
突破上轨,且Rsi没有超卖时做多,价格回归中轨时平仓
代码:
seting = {'name': 'BB', 'symbol': 'ETHUSDT', 'kTime': '15m', 'bb_len': 129, 'bb_mult': 2.259, 'rsi_len': 22, 'rsi_long_min': 15, 'rsi_long_max': 76, 'rsi_short_min': 12, 'rsi_short_max': 74, 'buy': 1, 'buyZhiying': 13.037, 'buyZhisun': 8.014, 'sell': 1, 'sellZhiying': 5.084, 'sellZhisun': 13.086}
"""
布林带策略
"""
def BB(r, df, seting):
df['ma'] = SMA(r, seting['bb_len'], 'Close')
df['mult'] = seting['bb_mult'] * talib.STDDEV(df['Close'].values, timeperiod=seting['bb_len'])
df['upper'] = df['ma'] + df['mult']
df['lower'] = df['ma'] - df['mult']
df['rsi'] = talib.RSI(df['Close'].values, timeperiod=14)
c = len(df)
for i in range(c):
if i > seting['bb_len'] and i+1 < c:
if df['Close'][i] > df['upper'][i] and df['Close'][i-1] < df['upper'][i-1] and\
df['rsi'][i] >= seting['rsi_long_min'] and df['rsi'][i] <= seting['rsi_long_max']:
df['side'].values[i] = 'BUY'
if df['Close'][i] < df['ma'][i] and df['Close'][i-1] > df['ma'][i-1]:
df['close'].values[i] = 'BUY'
if df['Close'][i] < df['lower'][i] and df['Close'][i-1] > df['lower'][i-1] and\
df['rsi'][i] >= seting['rsi_short_min'] and df['rsi'][i] <= seting['rsi_short_max']:
df['side'].values[i] = 'SELL'
if df['Close'][i] > df['ma'][i] and df['Close'][i-1] < df['ma'][i-1]:
df['close'].values[i] = 'SELL'
return df