Strategy vault / Mean reversion
Mean Reversion Bollinger Bands Trading Strategy with Rational Return Signal
This strategy is a quantitative trading system based on Bollinger Bands and price mean reversion principles. It monitors price deviation from the moving average, combined with Bollinger Bands breakout signals, to…

Overview
This strategy is a quantitative trading system based on Bollinger Bands and price mean reversion principles. It monitors price deviation from the moving average, combined with Bollinger Bands breakout signals, to trade when expecting price regression after market overbought/oversold conditions. The strategy uses percentage thresholds to measure price deviation and sets reasonable trigger conditions to filter false signals and improve trading accuracy.
Strategy Principles
The core logic is based on the following key elements:
- Uses 20-day moving average as middle band, with 2 standard deviations to construct Bollinger Bands
- Introduces 3.5% price deviation threshold to identify significant divergence
- Tracks price deviation status through is_outside variable
- Triggers trading signals when price returns within Bollinger Bands
- Specific trading rules:
- Long when price returns from deviation and breaks above upper band
- Short when price returns from deviation and breaks below lower band
Strategy Advantages
- Robust Mean Reversion Logic
- Based on statistical principle of price returning to mean
- Ensures trading opportunity significance through deviation threshold
- Comprehensive Risk Control
- Bollinger Bands provide clear volatility range reference
- Deviation status tracking avoids trading during extreme volatility
- Strong Parameter Adjustability
- Bollinger Bands parameters adjustable to instrument characteristics
- Deviation threshold can be set according to risk preference
Strategy Risks
- Trend Market Ineffectiveness Risk
- May generate frequent false signals in strong trend markets
- Recommend adding trend filter to identify market conditions
- Parameter Sensitivity Risk
- Improper parameter settings may affect strategy performance
- Requires parameter optimization through historical data backtesting
- Slippage Cost Risk
- Frequent trading may incur high transaction costs
- Recommend adding position time limits and cost controls
Strategy Optimization Directions
- Add Market Environment Recognition
- Introduce trend strength indicators like ADX
- Dynamically adjust parameters based on market conditions
- Improve Stop-Loss and Take-Profit Mechanisms
- Set dynamic stops based on ATR
- Introduce trailing stops to protect profits
- Optimize Trading Frequency
- Add minimum position holding time
- Set trading interval to control costs
Summary
This strategy captures market overbought/oversold opportunities through Bollinger Bands and mean reversion principles, effectively controlling trading risks with reasonable deviation thresholds and status tracking mechanisms. The strategy framework has good scalability and can adapt to different market environments through parameter optimization and functionality improvements. It's recommended to focus on risk control in live trading and adjust parameters according to specific instrument characteristics.
Source Pine Script
/*backtest
start: 2024-12-06 00:00:00
end: 2025-01-04 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Estratégia com Bandas de Bollinger e Sinal de Retorno", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=200)
// Configurações das Bandas de Bollinger
length = input.int(20, title="Período da média")
mult = input.float(2.0, title="Desvio padrão")
bbBasis = ta.sma(close, length)
bbUpper = bbBasis + mult * ta.stdev(close, length)
bbLower = bbBasis - mult * ta.stdev(close, length)
// Configuração para a distância da média
percent_threshold = input.float(3.5, title="Distância da média (%)") / 100
dist_from_mean = 0.0
trigger_condition = false
if not na(bbBasis)
dist_from_mean := math.abs(close - bbBasis) / bbBasis
trigger_condition := dist_from_mean >= percent_threshold
// Variáveis para identificar o estado do afastamento
var bool is_outside = false
var color candle_color = color.new(color.white, 0)
if trigger_condition
is_outside := true
if is_outside and close <= bbUpper and close >= bbLower
is_outside := false
candle_color := color.new(color.blue, 0) // Atribui uma cor válida
else
candle_color := color.new(color.white, 0)
// Aplicar cor às velas
barcolor(candle_color)
// Plotar Bandas de Bollinger
plot(bbBasis, color=color.yellow, title="Média")
plot(bbUpper, color=color.red, title="Banda Superior")
plot(bbLower, color=color.green, title="Banda Inferior")
// Lógica de entrada e saída
longCondition = not is_outside and close > bbUpper
if (longCondition)
strategy.entry("Buy", strategy.long)
shortCondition = not is_outside and close < bbLower
if (shortCondition)
strategy.entry("Sell", strategy.short)
Published by ChaoZhang on the FMZ strategy square · last modified 2025-01-06. 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/Mean-Reversion-Bollinger-Bands-Trading-Strategy-with-Rational-Return-Signal.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
- Multi Indicator Reversal Point Capture Trading StrategyPine Script · Mean reversion · 1d
- Reversal Trading Strategy with Bollinger Bands RSI ADX and ATRPine Script · Mean reversion · 1h
- Multi Indicator Trend Reversal Volatility Conditional Selective Options Selling StrategyPine Script · Mean reversion · 1h
- Triple Indicator Momentum Reversal StrategyPine Script · Mean reversion · 2h
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d
- Bollinger Bands ATR Risk Reward Trading StrategyPine Script · Mean reversion · 1d