The Bollinger Bands Tracking Strategy
The Bollinger Bands tracking strategy is a quantitative trading strategy based on Bollinger Bands. It calculates the upper and lower rails of the Bollinger Bands of a stock and sets buy and sell conditions to track…

Overview
The Bollinger Bands tracking strategy is a quantitative trading strategy based on Bollinger Bands. It calculates the upper and lower rails of the Bollinger Bands of a stock and sets buy and sell conditions to track the market. When the price touches the lower rail of the Bollinger Bands, the stock is considered undervalued, Thus providing more room for growth and generating a buy signal; when the price rises and touches the upper rail, the stock is considered overvalued, genTherefore considered to beerating a sell sign.
Strategy Principle
The core indicator of this strategy is Bollinger Bands. Bollinger Bands consist of three lines: middle rail, upper rail and lower rail. The middle rail is the n-day moving average closing price; the upper rail is the middle rail + k times the n-day standard deviation of the closing price; the lower rail is the middle rail - k times the n-day standard deviation of the closing price. The k value is usually set to 2. When the stock price is lower than the lower rail, it is at a relatively low price level, Therefore considered to be lowervalued, generating a buy signal; when the stock price is higher than the upper rail, it is at a relatively high price level and is considered overvalued, generating a sell signal.
Specifically, this strategy first calculates the 20-day moving average of closing prices as the middle rail, and then calculates twice the 20-day standard deviation of closing prices as the bandwidth. The upper rail is the middle rail + bandwidth and the lower rail is the middle rail - bandwidth. It then sets the buy condition to be closing price lower than the lower rail, and sell condition to be closing price higher than the upper rail. It generates a buy signal when closing price is below the lower rail, and a sell signal when closing price is above the upper rail.
Advantage Analysis
This strategy has the following advantages:
- The principle is simple and easy to understand and implement.
- It can track market trends and automatically generate buy and sell signals.
- The risk of drawdown is relatively small with certain tracking stop-loss function.
- It can filter out false breakouts and avoid wrong operations in sideways markets.
- Parameters like period and standard deviation multiplier can be adjusted to adapt to different stocks and market environments.
Risk Analysis
There are also some risks with this strategy:
- Bollinger Bands is not a perfect indicator for buy and sell points, signals may lag.
- It cannot predict extreme market conditions, face black swan events like financial crises.
- Stock price may run on one side of the bands for long periods, resulting in insufficient signals.
- Parameter settings like period length need optimization, otherwise it may be too sensitive or inert.
Corresponding solutions:
- Combine with other indicators to confirm timing of trades
- Set stop loss and take profit to control maximum loss
- Optimize parameters to improve adaptability
- Adopt composite strategies to avoid sole reliance
Optimization Directions
The main optimization directions for this strategy includes:
- Optimize Bollinger Bands parameters like trying different period lengths and standard deviation multiplier to find the optimal fitting parameters.
- Incorporate other indicators like KDJ, MACD etc. to filter buy/sell decisions to avoid Bollinger Bands lagging issue.
- Apply machine learning algorithms to guide optimal parameter settings.
- Use deep learning to predict probability of price breaking out of bands.
- Adopt composite strategies with backup trading strategies to avoid excessive dependence on single strategy.
Conclusion
Overall, Bollinger Bands tracking strategy is a relatively simple and practical quantitative trading strategy. It can automatically track price trends and also provide buy and sell signals. The pros are easy implementation, smaller risks, filtering false breakouts. The cons are certain lagging, inability to face extreme market conditions like black swans. This strategy can be further enhanced through optimizing parameters and indicators, using more advanced techniques like machine learning. In summary, combining Bollinger Bands strategies with other technical strategies can form a robust and efficient quantitative trading system.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 20 | Bollinger Bands Length |
| v_input_2 | 2 | Multiplier |
Source Pine Script
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Bollinger Bands Strategy", shorttitle="BB Strategy", overlay=true)
// Input parameters
length = input(20, title="Bollinger Bands Length")
mult = input(2, title="Multiplier")
// Calculate Bollinger Bands
basis = ta.sma(close, length)
bb_upper = basis + mult * ta.stdev(close, length)
bb_lower = basis - mult * ta.stdev(close, length)
// Buy and sell conditions
buy_condition = close < bb_lower
sell_condition = close > bb_upper
// Execute trades
strategy.entry("Buy", strategy.long, when=buy_condition)
strategy.entry("Sell", strategy.short, when=sell_condition)
// Plotting Bollinger Bands on the chart
plot(bb_upper, color=color.red, title="Upper Band")
plot(bb_lower, color=color.green, title="Lower Band")
plot(basis, color=color.blue, title="Basis")
// Highlighting buy and sell signals on the chart
bgcolor(buy_condition ? color.new(color.green, 90) : na)
bgcolor(sell_condition ? color.new(color.red, 90) : na)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-29. 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/The-Bollinger-Bands-Tracking-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