Dynamic Bollinger Breakout Strategy
This strategy is a breakout trading strategy based on the Bollinger Bands indicator. It calculates the upper and lower rails of the Bollinger Bands and combines them with dynamically adjustable buy and sell…

Overview
This strategy is a breakout trading strategy based on the Bollinger Bands indicator. It calculates the upper and lower rails of the Bollinger Bands and combines them with dynamically adjustable buy and sell thresholds to automate trading of BTCUSDT on Binance.
Strategy Logic
The core indicator of this strategy is Bollinger Bands. Bollinger Bands consist of an N-day moving average and upper and lower bands plotted at a standard deviation level above and below it. The Bollinger Bands in this strategy have a length of 20 days and a standard deviation multiplier of 2. When the price approaches or touches the lower rail of the Bollinger Bands, it is considered oversold, and the strategy will open a long position. When the price approaches or touches the upper rail, it is considered overbought, and the strategy will close long positions.
In addition to the Bollinger Bands indicator, this strategy also introduces two adjustable parameters: buy threshold and sell threshold. The buy threshold defaults to 58 points below the lower band and serves as the entry condition for opening long positions. The sell threshold defaults to 470 points above the lower band and serves as the exit condition for closing positions. These thresholds can be dynamically adjusted based on actual market conditions and backtest results to make the strategy more flexible.
When the buy condition is met, the strategy will open a long position using 10% of the account equity. After opening the long position, if the price rises to hit the stop loss level (-125%), positions will be closed by stop loss orders. When the price rises to trigger the sell threshold, the strategy will choose to close all positions to collect profits.
Advantage Analysis
The main advantages of this strategy include:
- Using Bollinger Bands can capture opportunities when prices abnormally deviate from bands and profit from reversals
- Introducing adjustable buy and sell thresholds optimizes entry and exit points
- Taking partial position sizes controls risk
- Setting stop loss condition avoids further losses
- Backtesting with 5-min intervals can capture short-term trading opportunities in a timely manner
Risk Analysis
There are also some risks with this strategy:
- Bollinger Bands itself is not 100% reliable, prices may oscillate lower for a long time before dropping again
- Improper threshold settings may cause missing the best entry or exit points
- Stop loss setting too loose may fail to stop loss in time, or too tight may cause stop loss too sensitive
- Improper backtesting period selection may take some occasional profits as stable income
Countermeasures:
- Combine more indicators to judge market conditions and avoid false signals of Bollinger Bands
- Test and optimize threshold parameters to find optimal combination
- Test and optimize stop loss conditions to find a balance
- Adopt longer backtesting period to examine stability of the strategy
Optimization Directions
The strategy can be further optimized in the following aspects:
- Try combining other indicators like KD, RSI to set stricter entry rules, avoid entering too early or too late
- Test different combinations of Bollinger Bands parameters to optimize band length and standard deviation multiplier
- Optimize buy and sell thresholds to improve profit rate
- Try adopting dynamic ATR-based stop loss ratio to match market volatility
- Optimize position sizing, e.g. appropriately pyramiding positions when in profit to control single loss risk
Summary
In summary, this is an overall simple and practical breakout strategy. It adopts Bollinger Bands to identify reversal opportunities and sets dynamic thresholds for entry and exit. Meanwhile, reasonable position sizing and stop loss conditions are utilized to control risks. After optimizing several key parameters, this strategy can yield relatively steady returns. It is suitable for algorithmic trading and can also serve as an auxiliary tool for stock picking or gauging market sentiment. Generally speaking, this strategy has strong practicality and extensibility.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 20 | Bollinger Bands period |
| v_input_2 | 2 | Standard deviation multiple |
| v_input_3 | 58 | Buy threshold |
| v_input_4 | 470 | Sell threshold |
Source Pine Script
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SuperDS_BTC
//@version=5
strategy("Bollinger Bands strategy long5min", overlay=true)
// Bollinger Bands calculation
length = input(20, title="Bollinger Bands period")
mult = input(2.0, title="Standard deviation multiple")
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper = basis + dev
lower = basis - dev
// Calculate purchase quantity: check the position size each time
// Each purchase uses a total of10%
position_size = strategy.equity * 10 / close
// Define adjustable threshold
buy_threshold = input(58, title="Buy threshold")
exit_threshold = input(470, title="Sell threshold")
// Buy condition: when the current price is below the lower Bollinger Band minus. buy_threshold
buy_condition = close < lower - buy_threshold
// Sell conditions and position closing conditions
exit_condition = close > lower + exit_threshold
// Buy logic
if buy_condition
strategy.entry("BuyLong", strategy.long, qty=position_size, comment="LongBTC")
// Sell logic
if exit_condition
strategy.close("BuyLong")
// Stop-loss logic
stop_loss_percent = -1.25 //Stop-loss percentage is-125%
if strategy.position_size > 0
position_profit_percent = (strategy.position_avg_price - close) / strategy.position_avg_price * 100
if position_profit_percent <= stop_loss_percent
strategy.close("BuyLong")Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-26. 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/Dynamic-Bollinger-Breakout-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
- Adaptive Bollinger Breakout with Moving Average Quantitative Strategy SystemPine Script · Breakout · 1h
- BB Breakout StrategyPine Script · Breakout · 1d
- Bollinger Band Breakout Trend Following StrategyPine Script · Breakout · 1d
- Bollinger Band Channel Breakout Trading StrategyPine Script · Breakout · 1d
- Bollinger Band T3 Moving Average StrategyPine Script · Breakout · 10m
- Bollinger Bands Breakout Trading StrategyPine Script · Breakout · 1h