该策略基于布林带指标,主要思想是在价格突破布林带上轨或下轨后,等待价格回归到布林带内部,然后在回归点建立与突破方向相同的头寸。该策略利用了价格在极端区域往往会出现反转的特点,通过布林带突破和回归的组合条件来捕捉市场转折点,以期获得更高的胜率。
布林带突破回归交易策略是一个简单实用的量化交易策略。它利用价格对极端情况的反应,通过布林带工具构建开平仓条件,能够在一定程度上捕捉趋势起始点和终结点,控制频繁交易。同时该策略也存在参数选择、震荡行情下表现不佳、对趋势把握不足等问题。通过细节的优化以及与其他信号的结合,有望进一步提升该策略的适应性和鲁棒性。
/*backtest start: 2024-02-01 00:00:00 end: 2024-02-27 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy(shorttitle="BB", title="Bollinger Bands", overlay=true) length = input.int(20, minval=1) maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]) src = input(close, title="Source") mult = input.float(1.7, minval=0.001, maxval=50, title="StdDev") ma(source, length, _type) => switch _type "SMA" => ta.sma(source, length) "EMA" => ta.ema(source, length) "SMMA (RMA)" => ta.rma(source, length) "WMA" => ta.wma(source, length) "VWMA" => ta.vwma(source, length) basis = ma(src, length, maType) dev = mult * ta.stdev(src, length) upper = basis + dev lower = basis - dev offset = input.int(0, "Offset", minval = -500, maxval = 500) plot(basis, "Basis", color=#FF6D00, offset = offset) p1 = plot(upper, "Upper", color=#2962FF, offset = offset) p2 = plot(lower, "Lower", color=#2962FF, offset = offset) fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95)) break_up = close > upper break_down = close < lower inside = close > lower and close < upper sell_condition = break_up[1] and inside buy_condition = break_down[1] and inside // Conditions to close trades close_sell_condition = close > basis close_buy_condition = close < basis trade_condition = sell_condition or buy_condition // Tracking the high of the breakout candle var float peak = na if (not trade_condition) peak := close if (break_up and peak < high) peak := high if (break_down and peak > low) peak := low // Entering positions if (buy_condition) strategy.entry("Buy", strategy.long) if (sell_condition) strategy.entry("Sell", strategy.short) // Exiting positions when close crosses the basis if (strategy.position_size > 0 and close_sell_condition) // If in a long position and close crosses above basis strategy.close("Buy") if (strategy.position_size < 0 and close_buy_condition) // If in a short position and close crosses below basis strategy.close("Sell")