Strategy vault / Mean reversion
Bollinger Band Mean Reversion Trading Strategy
This is a mean reversion trading strategy based on Bollinger Bands. It combines mean reversion trading and risk management mechanisms to capture short-term reversal opportunities in trending markets.

Overview
This is a mean reversion trading strategy based on Bollinger Bands. It combines mean reversion trading and risk management mechanisms to capture short-term reversal opportunities in trending markets.
Strategy Logic
The strategy uses 20-day Bollinger Bands to identify overextended price areas. It goes short when price nears the upper band and goes long when price nears the lower band, profiting from eventual reversals.
It also sets stop loss and take profit based on ATR. The stop loss is set at price breaking the moving average minus 2 times ATR. Take profit is set at price plus 3 times ATR. This effectively controls the risk per trade.
Specifically, the strategy includes:
- Calculate 20-day Bollinger Bands upper band, lower band and moving average
- Calculate 14-day ATR
- Long when price crosses above lower band; Short when price crosses below upper band
- Set stop loss at price minus 2 times ATR and take profit at price plus 3 times ATR when long
- Set stop loss at price plus 2 times ATR and take profit at price minus 3 times ATR when short
Advantage Analysis
The main advantages are:
- Bollinger Bands effectively identify overextended price areas
- Profit from reversals through mean reversion
- ATR stops set risk controls
- Positive backtest results with multiple profitable trades
Risk Analysis
Potential risks include:
- Failed reversal risk if price continues trending
- Stop loss skipped risk from price gaps
- Parameter optimization required for changing markets
Solutions:
- Strictly follow stop loss rules to limit loss per trade
- Optimize parameters to suit current markets
- Use options or other tools to hedge gap risk
Optimization Directions
The strategy can be further optimized by:
- Testing different moving averages for best parameters
- Adding filters to improve trend determination
- Adjusting ATR multiples to fine tune stops and limits
- Incorporating dynamic exit mechanisms based on market regimes
This will further enhance the stability and return profile.
Summary
In summary, the Bollinger Band mean reversion strategy with trend filters and risk management has demonstrated positive results. With continuous optimization and enhancements, it holds potential for steady and high-quality excess returns.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 20 | Bollinger Bands Length |
| v_input_2 | 2 | Bollinger Bands Multiplier |
| v_input_3 | 2 | Stop Loss ATR Multiplier |
| v_input_4 | 3 | Take Profit ATR Multiplier |
Source Pine Script
/*backtest
start: 2022-12-20 00:00:00
end: 2023-08-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Mean Reversion with Risk Management", overlay=true)
// Inputs for Bollinger Bands and Risk Management
length = input(20, minval=1, title="Bollinger Bands Length")
mult = input(2.0, title="Bollinger Bands Multiplier")
stopLossATRMult = input(2.0, title="Stop Loss ATR Multiplier")
takeProfitATRMult = input(3.0, title="Take Profit ATR Multiplier")
// Bollinger Bands Calculation
src = close
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
plot(upper, "Upper Band", color=color.red)
plot(lower, "Lower Band", color=color.green)
// ATR for Stop Loss and Take Profit
atr = atr(14)
// Trading Conditions
longCondition = crossover(src, lower)
shortCondition = crossunder(src, upper)
// Order Execution with Stop Loss and Take Profit
if (longCondition)
sl = src - stopLossATRMult * atr
tp = src + takeProfitATRMult * atr
strategy.entry("Long", strategy.long, stop=sl, limit=tp)
if (shortCondition)
sl = src + stopLossATRMult * atr
tp = src - takeProfitATRMult * atr
strategy.entry("Short", strategy.short, stop=sl, limit=tp)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-27. 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-Band-Mean-Reversion-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 ATR Risk Reward Trading StrategyPine Script · Mean reversion · 1d
- Dual Moving Average RSI Synergy Options Quantitative Trading StrategyPine Script · Mean reversion · 1h
- Enhanced Bollinger Mean Reversion Quantitative StrategyPine Script · Mean reversion · 1d
- Multi Indicator Reversal Point Capture Trading StrategyPine Script · Mean reversion · 1d
- Multi Timeframe Adaptive Mean Reversion with Volume Analysis StrategyPine Script · Mean reversion · 1h
- Reversal Trading Strategy with Bollinger Bands RSI ADX and ATRPine Script · Mean reversion · 1h