Mean Reversion Framework [LTS]

- How far is price stretched away from VWAP in standard deviations?
- Is the current environment favorable or hostile to mean reversion?
- Are there momentum divergences supporting a reversal or trend continuation idea?
Core components
1. Adaptive VWAP with standard deviation bands
The framework builds around a dynamically anchored VWAP with statistical bands:
- VWAP line plotted from a rolling anchor point.
- Standard deviation bands: ±1σ, ±2σ, ±2.5σ, and ±3σ around VWAP.
- Extension zones: the area between ±2.5σ and ±3σ is highlighted as an “extension zone,” where price is statistically stretched from its mean.
Anchoring is automatic and timeframe-aware. When you change your charts timeframe, this will automatically adjust what VWAP you are looking at to make sure you're always using the anchoring research has shown to be most appropriate and relevant for that timeframe.
2. Reversion candle coloring
To highlight potentially climactic moves:
- The script tracks a configurable volume average and multiplier.
- When price touches the ±2.5σ extension zone and a candle meets one of these conditions, candles can be recolored:
Has above average volume, but below average candle body size.
Has lower volume than the previous candle. - An optional alert can be triggered when these extension touches occur.
The ideal reversion setup is a quick extension into the marked zone, which includes a high volume, small body candle at its peak, surrounded by lower volume candles in opposite directions. This shows an energetic push in one direction, followed by exhaustion and a fade back toward the mean.
3. Volatility regime detection
The script classifies the current volatility regime using ATR:
- Calculates ATR over a user-defined lookback.
- Computes the percentile rank of current ATR relative to its recent history.
- Labels the environment as:
- HIGH volatility (ATR percentile at or above the high threshold).
- LOW volatility (at or below the low threshold).
- MODERATE otherwise.
- HIGH volatility (ATR percentile at or above the high threshold).
The current regime and ATR percentile are displayed on the dashboard and can be used as context for whether mean-reversion setups may be more or less favorable. Alerts can fire when volatility crosses into high or low regimes so users can adjust expectations or strategies if desired.
4. RSI & Stochastic divergence framework
The indicator includes a combined divergence engine using RSI and Stochastic:
- User-configurable RSI length.
- User-configurable Stochastic K/D parameters.
- Pivot-based detection with left/right lookbacks and a max lookback window.
- Two main categories:
- Regular divergences – potential reversal context.
- Hidden divergences – potential trend continuation context.
- Regular divergences – potential reversal context.
For both RSI and Stochastic, the script looks for:
- Bullish regular: price lower low vs. oscillator higher low.
- Bearish regular: price higher high vs. oscillator lower high.
- Hidden bullish: price higher low vs. oscillator lower low.
- Hidden bearish: price lower high vs. oscillator higher high.
When conditions are met, the script will:
- Plot labels on the price chart:
🔃 icons for regular (reversal) divergences.
⏩ icons for hidden (continuation) divergences. - Combine RSI and Stochastic confirmation into a single label when both agree, with tooltips explaining:
Price structure (HH/HL/LL/LH).
Which oscillator(s) confirmed the divergence.
Whether the pattern suggests potential reversal or continuation. - Optionally trigger alerts for each divergence type when alerts are enabled.
Divergence labels are based on confirmed pivots, so they appear with a delay relative to the pivot bar. They are not predictive and should be treated as contextual information rather than standalone trade signals.
5. Dashboard overlay
An on-chart dashboard summarizes the most important state variables in a compact table:
- VWAP Anchor – shows the effective anchor logic currently in use (“Session/Week/Month”, “5-Day Rolling” or “Yearly (Jan 1)”).
- Alert Status – ACTIVE, COOLDOWN, or DISABLED.
- Volatility Regime – HIGH / MODERATE / LOW with the current ATR percentile.
- VWAP Value – current VWAP price.
- Price vs VWAP – distance of price from VWAP in standard deviations (σ).
- ATR – current ATR value for the selected length.
The dashboard can be toggled on or off and moved to any corner of the chart (top/bottom, left/right).
6. Alert system & cooldown
The script defines multiple alert conditions so users can build their own rules around mean reversion and volatility changes:
- Extension zone alerts:
Price enters upper extension (≥ +2.5σ).
Price enters lower extension (≤ −2.5σ).
Price enters any extension zone.
High-volume candle touching an extension zone. - Divergence alerts:
Regular bullish / bearish divergence.
Hidden bullish / bearish divergence. - Volatility regime alerts:
- ATR percentile crosses into HIGH volatility.
- ATR percentile crosses into LOW volatility.
- ATR percentile crosses into HIGH volatility.
To reduce alert noise around VWAP resets, there is an optional alert cooldown:
- At the start of a new VWAP period (session/5-day/yearly, depending on timeframe), the script can enter a cooldown phase.
- During cooldown, extension-related alerts are temporarily suppressed for a user-defined number of minutes.
- Volatility regime alerts remain active, as they reflect broader structural changes rather than short-term VWAP resets.
Users can disable the cooldown by setting its duration to 0.
نص برمجي للمستخدمين المدعوين فقط
يمكن فقط للمستخدمين الذين تمت الموافقة عليهم من قبل المؤلف الوصول إلى هذا البرنامج النصي. ستحتاج إلى طلب الإذن والحصول عليه لاستخدامه. يتم منح هذا عادةً بعد الدفع. لمزيد من التفاصيل، اتبع تعليمات المؤلف أدناه أو اتصل ب LHAMA-Trading مباشرة.
لا توصي TradingView بالدفع مقابل برنامج نصي أو استخدامه إلا إذا كنت تثق تمامًا في مؤلفه وتفهم كيفية عمله. يمكنك أيضًا العثور على بدائل مجانية ومفتوحة المصدر في نصوص مجتمعنا.
تعليمات المؤلف
Skip the drama, ride the LHAMA!
إخلاء المسؤولية
نص برمجي للمستخدمين المدعوين فقط
يمكن فقط للمستخدمين الذين تمت الموافقة عليهم من قبل المؤلف الوصول إلى هذا البرنامج النصي. ستحتاج إلى طلب الإذن والحصول عليه لاستخدامه. يتم منح هذا عادةً بعد الدفع. لمزيد من التفاصيل، اتبع تعليمات المؤلف أدناه أو اتصل ب LHAMA-Trading مباشرة.
لا توصي TradingView بالدفع مقابل برنامج نصي أو استخدامه إلا إذا كنت تثق تمامًا في مؤلفه وتفهم كيفية عمله. يمكنك أيضًا العثور على بدائل مجانية ومفتوحة المصدر في نصوص مجتمعنا.
تعليمات المؤلف
Skip the drama, ride the LHAMA!