Bollinger Bands Based Intelligent Tracking Trading Strategy
This strategy is designed based on the Bollinger Bands indicator to go short when price breaks above the upper band and go long when price breaks below the lower band, realizing intelligent tracking trading.

Overview
This strategy is designed based on the Bollinger Bands indicator to go short when price breaks above the upper band and go long when price breaks below the lower band, realizing intelligent tracking trading.
Strategy Logic
The strategy uses the middle line, upper band and lower band of the Bollinger Bands as the base indicators. The middle line is the moving average of the closing prices over n days. The upper band is the middle line shifted up by two standard deviations while the lower band is shifted down by two standard deviations. When price breaks the lower band upwards, go long. When price breaks the upper band downwards, go short. This allows intelligent tracking of price based on market volatility.
Specifically, the strategy mainly judges two metrics:
ta.crossover(source, lower): closing price breaks above lower band, go long
ta.crossunder(source, upper): closing price breaks below upper band, go short
When the exit condition triggers, use strategy.cancel() function to flatten existing position.
Advantage Analysis
The main advantages of this strategy are:
- Based on Bollinger Bands indicator, able to capture market volatility and effectively track price trend
- Clear and simple logic, easy to understand and implement
- Customizable parameters like period length and standard deviation multiplier, highly adaptable
- Configurable stop loss, break-even or trailing stop mechanisms to optimize strategy performance
Risk Analysis
There are also some risks with this strategy:
- Bollinger Bands breakouts prone to false signals
- Performance relies on parameter optimization, improper parameters may impact profitability
- Tracking stop loss difficult, unable to effectively control single trade loss
Corresponding solutions:
- Add filters with other indicators to avoid false breakouts
- Test parameters thoroughly to find optimal parameter set
- Add moving or trend-following stop loss mechanisms
Optimization Directions
The strategy can be further optimized by:
- Adding other indicators to determine trend direction, avoiding unsuitable market conditions for Bollinger strategy
- Testing different period lengths to find the optimal one
- Incorporating moving or trailing stop mechanisms to effectively control single trade loss
Conclusion
This strategy is designed based on the Bollinger Bands indicator, using price breakouts of upper and lower bands to automatically track prices. The logic is simple and sensitive to market volatility. Further optimizations can be done via parameter tuning and stop loss mechanisms. Overall this strategy works well for indices and commodities with higher volatility. Traders can backtest and optimize based on their trading preference to derive an astika trading strategy.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 20 | length |
| v_input_float_1 | 2 | mult |
Source Pine Script
/*backtest
start: 2023-12-17 00:00:00
end: 2024-01-16 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Bollinger Bands Strategy with alerts (incl. pending orders) via TradingConnector to Forex", overlay=true)
source = close
length = input.int(20, minval=1)
mult = input.float(2.0, minval=0.001, maxval=50)
basis = ta.sma(source, length)
dev = mult * ta.stdev(source, length)
upper = basis + dev
lower = basis - dev
buyEntry = ta.crossover(source, lower)
sellEntry = ta.crossunder(source, upper)
if (ta.crossover(source, lower))
strategy.entry("BBandLE", strategy.long, stop=lower, oca_name="BollingerBands", comment="BBandLE")
alert(message='long price='+str.tostring(lower), freq=alert.freq_once_per_bar_close)
else
strategy.cancel(id="BBandLE")
alert(message='cancel long', freq=alert.freq_once_per_bar_close)
if (ta.crossunder(source, upper))
strategy.entry("BBandSE", strategy.short, stop=upper, oca_name="BollingerBands", comment="BBandSE")
alert(message='short price='+str.tostring(upper), freq=alert.freq_once_per_bar_close)
else
strategy.cancel(id="BBandSE")
alert(message='cancel short', freq=alert.freq_once_per_bar_close)
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
//Lines of code added to the original built-in script: 14, 17, 20 and 23 only.
//They trigger alerts ready to be executed on real markets through TradingConnector
//available for Forex, indices, crypto, stocks - anything your broker offers for trading via MetaTrader4/5
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-17. 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-Based-Intelligent-Tracking-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
- 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