OPEN-SOURCE SCRIPT
Mean-Reversion Indicator_V2_Samlee

Overview
This is the second version of my mean reversion indicator. It combines a moving average with adaptive standard deviation bands to detect when the price deviates significantly from its mean. The script provides automatic entry/exit signals, real-time PnL tracking, and shaded trade zones to make mean reversion trading more intuitive.
Core Logic
Mean benchmark: Simple Moving Average (MA).
Volatility bands: Standard deviation of the spread (close − MA) defines upper and lower bands.
Trading rules:
Price breaks below the lower band → Enter Long
Price breaks above the upper band → Enter Short
Price reverts to MA → Exit position
What’s different vs. classic Bollinger/Keltner
Bandwidth is based on the standard deviation of the price–MA spread, not raw closing prices.
Entry signals use previous-bar confirmation to reduce intrabar noise.
Exit rule is a mean-touch condition, rather than fixed profit/loss targets.
Enhanced visualization:
A shaded box dynamically shows the distance between entry and current/exit price, making it easy to see profit/loss zones over the holding period.
Instant PnL labels display current position side (Long/Short/Flat) and live profit/loss in both pips and %.
Entry and exit points are clearly marked on the chart with labels and exact prices.
These visualization tools go beyond what most indicators provide, giving traders a clearer, more practical view of trade evolution.
Key Features
Automatic detection of position status (Long / Short / Flat).
Chart labels for entries (“Entry”) and exits (“Exit”).
Real-time floating PnL calculation in both pips and %.
Info panel (top-right) showing entry price, current price, position side, and PnL.
Dynamic shading between entry and current/exit price to visualize profit/loss zones.
Usage Notes & Risk
Mean reversion may underperform in strong trending markets; parameters (len_ma, len_std, mult) should be validated per instrument and timeframe.
Works best on relatively stable, mean-reverting pairs (e.g., AUDNZD).
Risk management is essential: use independent stop-loss rules (e.g., limit risk to 1–2% of equity per trade).
This script is provided for educational purposes only and is not financial advice.
This is the second version of my mean reversion indicator. It combines a moving average with adaptive standard deviation bands to detect when the price deviates significantly from its mean. The script provides automatic entry/exit signals, real-time PnL tracking, and shaded trade zones to make mean reversion trading more intuitive.
Core Logic
Mean benchmark: Simple Moving Average (MA).
Volatility bands: Standard deviation of the spread (close − MA) defines upper and lower bands.
Trading rules:
Price breaks below the lower band → Enter Long
Price breaks above the upper band → Enter Short
Price reverts to MA → Exit position
What’s different vs. classic Bollinger/Keltner
Bandwidth is based on the standard deviation of the price–MA spread, not raw closing prices.
Entry signals use previous-bar confirmation to reduce intrabar noise.
Exit rule is a mean-touch condition, rather than fixed profit/loss targets.
Enhanced visualization:
A shaded box dynamically shows the distance between entry and current/exit price, making it easy to see profit/loss zones over the holding period.
Instant PnL labels display current position side (Long/Short/Flat) and live profit/loss in both pips and %.
Entry and exit points are clearly marked on the chart with labels and exact prices.
These visualization tools go beyond what most indicators provide, giving traders a clearer, more practical view of trade evolution.
Key Features
Automatic detection of position status (Long / Short / Flat).
Chart labels for entries (“Entry”) and exits (“Exit”).
Real-time floating PnL calculation in both pips and %.
Info panel (top-right) showing entry price, current price, position side, and PnL.
Dynamic shading between entry and current/exit price to visualize profit/loss zones.
Usage Notes & Risk
Mean reversion may underperform in strong trending markets; parameters (len_ma, len_std, mult) should be validated per instrument and timeframe.
Works best on relatively stable, mean-reverting pairs (e.g., AUDNZD).
Risk management is essential: use independent stop-loss rules (e.g., limit risk to 1–2% of equity per trade).
This script is provided for educational purposes only and is not financial advice.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.