OPEN-SOURCE SCRIPT
Mean Reversion — BB + Z-Score + RSI + EMA200 (TP at Opposite Z)

This is a systematic mean-reversion framework for index futures and other liquid assets.
This strategy combines Bollinger Bands, Z-Score dislocation, RSI extremes, and a trend-filtering EMA200 to capture short-term mean-reversion inefficiencies in NQ1!. It is designed for high-volatility conditions and uses a precise exit model based on opposite-side Z-Score targets and dynamic mid-band failure detection.
🔍 Entry Logic (Mean Reversion) :
The strategy enters trades only when multiple confluence signals align:
Long Setup
Price at or below the lower Bollinger Band
Z-Score ≤ –Threshold (deep statistical deviation)
RSI ≤ oversold level
Price below the EMA-200 (countertrend mean-reversion only)
Cooldown must be completed
No open position
Short Setup
Price at or above the upper Bollinger Band
Z-Score ≥ Threshold
RSI ≥ overbought level
Price above the EMA-200
Cooldown complete
No open position
This multi-signal gate filters out weak reversions and focuses on mature dislocations.
🎯 Take-Profit Model: Opposite-Side Z-Score Target :
Once in a trade, take-profit is set by solving for the price where the Z-Score reaches the opposite side:
Long TP = Z = +Threshold
Short TP = Z = –Threshold
This creates a symmetric statistical exit based on reverting to equilibrium plus overshoot.
🛡️ Stop-Loss System (Volatility-Aware) :
Stop losses combine:
A fixed base stop (points)
A standard-deviation volatility component
This adapts the SL to regime changes and avoids being shaken out during rare volatility spikes.
⏳ Half-Life Exit :
If a trade has not reverted within a fixed number of bars, it automatically closes.
This prevents “mean-reversion traps” during trending periods.
📉 Advanced Mid-Band Exit Logic (BB Basis Failure) :
This is the unique feature of the system.
After entry:
Wait for price to cross the Bollinger Basis (middle band) in the direction of the mean.
Start a 5-bar delay timer.
After 5 bars, the strategy becomes “armed.”
Once armed:
If price fails back through the mean, exit immediately.
Intrabar exits trigger precisely (with tick-level precision if Bar Magnifier is enabled).
This protects profits and exits trades at the first sign of mean-failure.
⏱️ Cooldown System :
After each closed trade, a cooldown period prevents immediate re-entry.
This avoids clustering and improves statistical independence of trades.
🖥️ What This Strategy Is Best For :
High-volatility intraday NQ conditions
Statistical mean reversion with structured confluence
Traders who want clean, rule-based entries
Avoiding trend-day traps using EMA and half-life logic
📊 Included Visual Elements :
Bollinger Bands (Upper, Basis, Lower)
BUY/SELL markers at signal generation
Optional alerts for automated monitoring
🚀 Summary :
This is a precision mean-reversion system built around volatility bands, statistical dislocation, and price-behavior confirmation. By combining Z-Score, RSI, EMA200 filtering, and a sophisticated mid-band failure exit, this model captures high-probability reversions while avoiding the common pitfalls of naive band-touch systems.
This strategy combines Bollinger Bands, Z-Score dislocation, RSI extremes, and a trend-filtering EMA200 to capture short-term mean-reversion inefficiencies in NQ1!. It is designed for high-volatility conditions and uses a precise exit model based on opposite-side Z-Score targets and dynamic mid-band failure detection.
🔍 Entry Logic (Mean Reversion) :
The strategy enters trades only when multiple confluence signals align:
Long Setup
Price at or below the lower Bollinger Band
Z-Score ≤ –Threshold (deep statistical deviation)
RSI ≤ oversold level
Price below the EMA-200 (countertrend mean-reversion only)
Cooldown must be completed
No open position
Short Setup
Price at or above the upper Bollinger Band
Z-Score ≥ Threshold
RSI ≥ overbought level
Price above the EMA-200
Cooldown complete
No open position
This multi-signal gate filters out weak reversions and focuses on mature dislocations.
🎯 Take-Profit Model: Opposite-Side Z-Score Target :
Once in a trade, take-profit is set by solving for the price where the Z-Score reaches the opposite side:
Long TP = Z = +Threshold
Short TP = Z = –Threshold
This creates a symmetric statistical exit based on reverting to equilibrium plus overshoot.
🛡️ Stop-Loss System (Volatility-Aware) :
Stop losses combine:
A fixed base stop (points)
A standard-deviation volatility component
This adapts the SL to regime changes and avoids being shaken out during rare volatility spikes.
⏳ Half-Life Exit :
If a trade has not reverted within a fixed number of bars, it automatically closes.
This prevents “mean-reversion traps” during trending periods.
📉 Advanced Mid-Band Exit Logic (BB Basis Failure) :
This is the unique feature of the system.
After entry:
Wait for price to cross the Bollinger Basis (middle band) in the direction of the mean.
Start a 5-bar delay timer.
After 5 bars, the strategy becomes “armed.”
Once armed:
If price fails back through the mean, exit immediately.
Intrabar exits trigger precisely (with tick-level precision if Bar Magnifier is enabled).
This protects profits and exits trades at the first sign of mean-failure.
⏱️ Cooldown System :
After each closed trade, a cooldown period prevents immediate re-entry.
This avoids clustering and improves statistical independence of trades.
🖥️ What This Strategy Is Best For :
High-volatility intraday NQ conditions
Statistical mean reversion with structured confluence
Traders who want clean, rule-based entries
Avoiding trend-day traps using EMA and half-life logic
📊 Included Visual Elements :
Bollinger Bands (Upper, Basis, Lower)
BUY/SELL markers at signal generation
Optional alerts for automated monitoring
🚀 Summary :
This is a precision mean-reversion system built around volatility bands, statistical dislocation, and price-behavior confirmation. By combining Z-Score, RSI, EMA200 filtering, and a sophisticated mid-band failure exit, this model captures high-probability reversions while avoiding the common pitfalls of naive band-touch systems.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.