This strategy is based on the Bollinger Bands indicator and generates trading signals when the price breaks through the upper or lower bands. It goes long when the price breaks above the upper band and goes short when the price breaks below the lower band. Additionally, if holding a long position, it closes the position when the price falls below the lower band; if holding a short position, it closes the position when the price breaks above the upper band. The strategy aims to capture market volatility, entering trades when price fluctuations intensify and exiting in a timely manner when prices reverse.
The BB Breakout Strategy is a trading strategy based on the Bollinger Bands indicator, seeking trading opportunities when prices break through the upper or lower bands. The strategy’s advantages are clear signals and easy implementation, with certain risk control measures in place. However, the strategy also has some limitations, such as potentially high trading frequency and signal lag. Therefore, in practical applications, improvements can be considered in areas such as signal confirmation, stop-loss optimization, and parameter optimization to enhance the strategy’s stability and profitability.
/*backtest start: 2023-06-08 00:00:00 end: 2024-06-13 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("BB Strategy", overlay=true) // Input parameters length = input.int(20, minval=1, title="Length") maType = input.string("SMA", "Basis MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]) src = input(close, title="Source") mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev") offset = input.int(0, "Offset", minval=-500, maxval=500, title="Offset") // Moving average function 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) // Calculate Bollinger Bands basis = ma(src, length, maType) dev = mult * ta.stdev(src, length) upper = basis + dev lower = basis - dev // Plot Bollinger Bands plot(basis, "Basis", color=color.blue, offset=offset) p1 = plot(upper, "Upper", color=color.red, offset=offset) p2 = plot(lower, "Lower", color=color.green, offset=offset) fill(p1, p2, title="Background", color=color.rgb(33, 150, 243, 95)) // Strategy logic longCondition = ta.crossover(close, upper) shortCondition = ta.crossunder(close, lower) // Strategy entries and exits if (longCondition) strategy.entry("Long", strategy.long) if (shortCondition) strategy.entry("Short", strategy.short) if (shortCondition and strategy.position_size > 0) strategy.close("Long") if (longCondition and strategy.position_size < 0) strategy.close("Short")