Bollinger Bands Breakout Quantitative Trading Strategy
This strategy calculates the upper band, middle band and lower band of Bollinger Bands and combines the closing price of K-line to implement Bollinger Bands breakout trading strategy. It goes long when price breaks…

Overview
This strategy calculates the upper band, middle band and lower band of Bollinger Bands and combines the closing price of K-line to implement Bollinger Bands breakout trading strategy. It goes long when price breaks through the upper band and goes short when price breaks through the lower band. Stop loss and take profit prices are also set.
Strategy Principle
Calculate the middle band SMA of Bollinger Bands with period 60, representing the middle band of price trend.
Calculate the upper band and lower band of Bollinger Bands. The upper band is middle band + 2 times standard deviation and the lower band is middle band - 2 times standard deviation. The band width is controlled by multiplier.
When closing price is greater than the upper band, go long. When closing price is less than the lower band, go short.
Set stop loss and take profit mechanism. The stop loss percentage is 1.5% and take profit percentage is 6%.
When price re-enters the Bollinger Bands or reaches stop loss/take profit price, close position.
Advantage Analysis
Bollinger Bands indicator has strong ability of trend judgment by breakout.
Simple strategy logic and easy to understand and implement.
Stop loss and take profit control risks.
Risk Analysis
Bollinger Bands breakout cannot accurately determine price trend reversal points, with the risk of false breakout.
Unreasonable stop loss and take profit settings may bring greater risks.
High trading frequency may be affected by transaction costs.
Optimization Directions
Combine with other indicators to filter out false signals, e.g. KDJ for trend and MACD for divergence.
Dynamically adjust Bollinger Bands parameters based on market volatility to calculate reasonable band width.
Optimize stop loss and take profit strategy, e.g. trailing stop or partial closing.
Consider transaction costs' impact and adjust holding period.
Conclusion
This strategy follows trend by Bollinger Bands breakout and has some positive effects. But false breakout may bring greater risks. Combining with other indicators and keep optimizing parameters can control risks and improve profitability.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 60 | length |
| v_input_float_1 | 2 | mult |
Source Pine Script
/*backtest
start: 2024-01-04 00:00:00
end: 2024-02-03 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Fuera Bolinga", overlay=true)
length = input.int(60, minval=1)
mult = input.float(2.0, minval=0.001, maxval=50)
take_profit_percentage = 6.0
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper = basis + dev
lower = basis - dev
stop_loss_percentage = 1.5
// Determinar si la vela cierra por fuera de las bandas
above_upper_band = close > upper
under_lower_band = close < lower
// Pintar las velas que cierran por fuera de las bandas
barcolor(above_upper_band ? color.new(#2cee32, 0) : na)
barcolor(under_lower_band ? color.new(#e02c2c, 0) : na)
// Entrada larga con stop loss y take profit
if (ta.crossover(close, upper))
strategy.entry("BBandLE", strategy.long, oca_name="BollingerBands", comment="BBandLE")
else
strategy.cancel(id="BBandLE")
// Entrada corta con stop loss y take profit
if (ta.crossunder(close, lower))
strategy.entry("BBandSE", strategy.short, oca_name="BollingerBands",comment="BBandSE")
else
strategy.cancel(id="BBandSE")
//// Salida de operación larga
if ((ta.crossunder(close, upper) or ta.crossunder(close, lower)) and (strategy.opentrades != 0))
strategy.close("BBandLE")
// Salida de operación corta
if ((ta.crossover(close, lower) or ta.crossover(close, upper)) and (strategy.opentrades != 0))
strategy.close("BBandSE")
// Plot de las bandas de Bollinger
plot(upper, color=color.new(#2cee32, 0), title="Upper Bollinger Band")
plot(lower, color=color.new(#e02c2c, 0), title="Lower Bollinger Band")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-04. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Bollinger-Bands-Breakout-Quantitative-Trading-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Bollinger Bands Dynamic Breakout StrategyPine Script · Breakout · 1h
- Cross boundary Dynamic Range Quantitative Trading Strategy Based on Bollinger BandsPine Script · Breakout · 3h
- Momentum Breakout Moving Average StrategyPine Script · Breakout · 1d
- Momentum Breakout Trading Strategy 440964Pine Script · Breakout · 5m
- Momentum Breakout Trading StrategyPine Script · Breakout · 4h
- Moving Average Crossover and Upper Rail Breakthrough Impulse StrategyPine Script · Breakout · 1m