Bollinger Breakout with Mean Reversion 4H Quantitative Trading Strategy
This strategy is a 4-hour timeframe quantitative trading system based on Bollinger Bands, combining trend breakout and mean reversion trading concepts. The strategy captures market momentum through Bollinger Bands…

Overview
This strategy is a 4-hour timeframe quantitative trading system based on Bollinger Bands, combining trend breakout and mean reversion trading concepts. The strategy captures market momentum through Bollinger Bands breakouts while using price mean reversion for profit-taking and implementing stop-loss for risk control. It employs 3x leverage, ensuring returns while thoroughly considering risk management.
Strategy Principles
The core logic is based on the following key elements:
- Uses 20-period moving average as the middle band, with 2 standard deviations for the volatility range
- Entry signals: Long when candle body (average of open and close) breaks above upper band, short when breaks below lower band
- Exit signals: Close long positions when two consecutive candles have both open and close prices below the upper band and close below open; reverse logic for short positions
- Risk control: Sets stop-loss at current candle high/low points to ensure controlled losses per trade
Strategy Advantages
- Clear trading logic: Combines trend and reversion trading approaches for good performance in various market conditions
- Comprehensive risk control: Implements dynamic stop-loss based on candle volatility for effective drawdown control
- False signal filtering: Confirms breakouts using candle body position rather than just closing price to reduce false breakout losses
- Sound money management: Dynamically adjusts position size based on account equity, balancing returns and risk
Strategy Risks
- Sideways market risk: May trigger frequent false breakout signals in ranging markets, leading to consecutive stops
- Leverage risk: 3x leverage may cause significant losses during extreme volatility
- Stop-loss setting risk: Using candle high/low points for stops may be too loose, increasing per-trade losses
- Timeframe dependency: 4-hour timeframe may react too slowly in certain market conditions, missing opportunities
Strategy Optimization Directions
- Implement trend filter: Add longer-term trend indicators to trade in primary trend direction
- Optimize stop-loss approach: Consider using ATR or Bollinger Band width for dynamic stop-loss distances
- Enhance position management: Dynamically adjust leverage based on volatility or trend strength
- Add market condition analysis: Incorporate volume or volatility indicators to identify market states for selective entry
Summary
This strategy combines Bollinger Bands' trend-following and mean-reversion characteristics, achieving stable returns in both trending and ranging markets through strict entry/exit conditions and risk control measures. Its core strengths lie in clear trading logic and comprehensive risk management system, but attention must be paid to leverage usage and market condition judgment optimization to further improve strategy stability and profitability.
Source Pine Script
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-10 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Bollinger 4H Follow", overlay=true, initial_capital=300, commission_type=strategy.commission.percent, commission_value=0.04)
// StartYear = input(2022,"Backtest Start Year")
// StartMonth = input(1,"Backtest Start Month")
// StartDay = input(1,"Backtest Start Day")
// testStart = timestamp(StartYear,StartMonth,StartDay,0,0)
// EndYear = input(2023,"Backtest End Year")
// EndMonth = input(12,"Backtest End Month")
// EndDay = input(31,"Backtest End Day")
// testEnd = timestamp(EndYear,EndMonth,EndDay,0,0)
lev = 3
// Input parameters
length = input.int(20, title="Bollinger Band Length")
mult = input.float(2.0, title="Bollinger Band Multiplier")
// Bollinger Bands calculation
basis = ta.sma(close, length)
upperBand = basis + mult * ta.stdev(close, length)
lowerBand = basis - mult * ta.stdev(close, length)
// Conditions for Open Long
openLongCondition = strategy.position_size == 0 and close > open and (close + open) / 2 > upperBand
// Conditions for Open Short
openShortCondition = strategy.position_size == 0 and close < open and (close + open) / 2 < lowerBand
// Conditions for Close Long
closeLongCondition = strategy.position_size > 0 and strategy.position_size > 0 and (close < upperBand and open < upperBand and close < open)
// Conditions for Close Short
closeShortCondition = strategy.position_size < 0 and strategy.position_size < 0 and (close > lowerBand and open > lowerBand and close > open)
// Long entry
if openLongCondition
strategy.entry("Long", strategy.long, qty=strategy.equity * lev / close)
strategy.exit("Long SL", from_entry="Long", stop=low) // Set Stop-Loss
// Short entry
if openShortCondition
strategy.entry("Short", strategy.short, qty=strategy.equity * lev / close)
strategy.exit("Short SL", from_entry="Short", stop=high) // Set Stop-Loss
// Long exit
if closeLongCondition
strategy.close("Long", comment = "TP")
// Short exit
if closeShortCondition
strategy.close("Short", comment = "TP")
// Plot Bollinger Bands
plot(upperBand, color=color.yellow, title="Upper Band")
plot(lowerBand, color=color.yellow, title="Lower Band")Published by ChaoZhang on the FMZ strategy square · last modified 2024-12-12. 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-Breakout-with-Mean-Reversion-4H-Quantitative-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
- BB Breakout StrategyPine Script · Breakout · 1d
- Bollinger Band Breakout Trend Following StrategyPine Script · Breakout · 1d
- EMA and Bollinger Bands Breakout StrategyPine Script · Breakout · 1h
- Follow Line StrategyPine Script · Breakout · 10m
- Momentum Breakout Moving Average StrategyPine Script · Breakout · 1d
- Momentum Breakout Trading Strategy 440964Pine Script · Breakout · 5m