This strategy is a trading strategy designed based on the Bollinger Bands dual standard deviation model. It uses the upper and lower rails of Bollinger Bands and one and two standard deviations as trading signals. It goes long when the price breaks through the upper rail and goes short when the price breaks through the lower rail. The strategy also uses one and two standard deviations as stop loss lines.
The strategy first calculates the middle rail, upper rail and lower rail of the Bollinger Bands. The middle rail is the SMA of CLOSE, the upper rail is middle rail + 2standard deviation, and the lower rail is middle rail - 2standard deviation. When the price breaks through the upper rail, a buy signal is generated to go long. When the price breaks through the lower rail, a sell signal is generated to go short. In addition, the strategy also plots the lines of middle rail + 1 standard deviation and middle rail - 1 standard deviation. They are used as stop loss lines. The specific logic is:
In general, this strategy is a typical Bollinger Bands breakout strategy. It uses dual standard deviations to increase the strictness of signal judgment and adopts dual stop loss lines to actively control risks. The strategy has some parameter optimization space. By adjusting parameters like middle rail period and standard deviation multiplier, better strategy performance can be obtained. At the same time, the strategy also faces the common problem of false breakouts in Bollinger Bands strategies. In addition, there is room for further improvement and optimization in the stop loss mechanism.
/*backtest start: 2022-12-11 00:00:00 end: 2023-12-17 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 // Bollinger Bands: Madrid : 14/SEP/2014 11:07 : 2.0 // This displays the traditional Bollinger Bands, the difference is // that the 1st and 2nd StdDev are outlined with two colors and two // different levels, one for each Standard Deviation strategy(shorttitle='MBB', title='Bollinger Bands', overlay=true) src = input(close) length = input.int(34, minval=1) mult = input.float(2.0, minval=0.001, maxval=50) basis = ta.sma(src, length) dev = ta.stdev(src, length) dev2 = mult * dev upper1 = basis + dev lower1 = basis - dev upper2 = basis + dev2 lower2 = basis - dev2 colorBasis = src >= basis ? color.blue : color.orange pBasis = plot(basis, linewidth=2, color=colorBasis) pUpper1 = plot(upper1, color=color.new(color.blue, 0), style=plot.style_circles) pUpper2 = plot(upper2, color=color.new(color.blue, 0)) pLower1 = plot(lower1, color=color.new(color.orange, 0), style=plot.style_circles) pLower2 = plot(lower2, color=color.new(color.orange, 0)) fill(pBasis, pUpper2, color=color.new(color.blue, 80)) fill(pUpper1, pUpper2, color=color.new(color.blue, 80)) fill(pBasis, pLower2, color=color.new(color.orange, 80)) fill(pLower1, pLower2, color=color.new(color.orange, 80)) // Entry conditions longCondition = ta.crossover(close, upper1) shortCondition = ta.crossunder(close, lower1) // Entry and exit strategy strategy.entry("Buy", strategy.long, when=longCondition) strategy.entry("Sell", strategy.short, when=shortCondition) strategy.close("Buy", when=shortCondition) strategy.close("Sell", when=longCondition)