OPEN-SOURCE SCRIPT
Zaktualizowano Volatility Pressure & Regime Analyzer

Volatility Pressure & Regime Analyzer [VPRA]
## What this script does
VPRA estimates **when a market is loading energy for an outsized move, how large that move could be, and whether the current regime favors chasing or fading the breakout**. It condenses this into one on-chart verdict panel, directional signal markers, a regime ribbon, and a forecast of the expected move in ATR and points.
It works on **any symbol, any market, any timeframe**. A related volatility index and a companion symbol (the underlying if you chart a derivative, or vice versa) are optional inputs that sharpen the analysis; both can be disabled and the model renormalizes to price-only mode automatically.
## Why these components are combined (mashup justification)
Each module answers a question the others cannot, and the signal only fires when their answers agree. None of them is a stock indicator pasted alongside another — they are inputs to a single pressure model:
1. **Compression (ATR percentile)** answers *"is energy being stored?"* Quiet ranges precede expansion, but compression alone says nothing about direction or timing.
2. **Implied-vs-realized volatility dislocation** (optional vol index) answers *"is the options market mispricing the calm?"* A large gap between implied and realized volatility marks complacency or stress that compression alone cannot see.
3. **Basis tension** (optional companion symbol) answers *"is positioning leaning?"* Momentum in the derivative-to-underlying spread, and outright backwardation, reveal funding pressure and de-risking invisible in a single price series.
4. **Convexity and trend inefficiency** (return acceleration, efficiency ratio) answer *"is price behavior becoming unstable?"*
These four are blended into one **Pressure score (0–100)**, percent-ranked against its own history so thresholds adapt to every symbol and timeframe.
5. **A variance-ratio regime filter** answers *"will the break run or get faded?"* The ratio of k-bar to 1-bar return variance classifies the tape as mean-reverting (pinning) or trending (amplifying). Breakouts in a pinning regime are statistically more likely to fail, so the script can label or skip them.
6. **A multi-timeframe trend filter (Ichimoku cloud bias on the chart TF + three higher TFs)** answers *"is the release direction supported by structure?"* It grades signals rather than generating them. Higher-timeframe values are taken from **closed bars by default, so the confluence grade does not repaint**.
7. **Session, expiry, gap and event context** scale the expected-move forecast: an expiry-afternoon release during a volatility spike forecasts a larger move than a sleepy mid-session one.
Removing any module degrades a specific, named capability — that is the test the combination was built to pass.
## How a signal is generated
A marker prints only when **all** of the following align: pressure has reached a high percentile of its own history within a short lookback ("loaded"), the current bar shows a genuine range expansion ("release"), the condition persists for a confirmation bar count, a debounce gap has passed, and (optionally) the regime and trend filters pass. Direction is scored from **trigger-break** (close beyond the prior N-bar extreme), **close location** within the bar, and short momentum.
Marker color encodes the inferred event type: expiry-session releases, volatility-co-movement squeezes (price and vol index moving together — a short-covering tell), or plain expansions. The glow ring encodes how many higher timeframes agree. An ⓘ label stores a full diagnostic snapshot (pressure, regime, instability, basis, energy, session, expected move) in its tooltip for every signal.
## How to use it
- Apply to a liquid symbol; set "This chart is" to Derivative or Underlying, point the companion and volatility-index inputs at your market's related symbols (or disable them), and set your session hours and expiry weekday.
- Read the panel top-down: **Regime** (chase vs fade), **Pressure/Energy** (how loaded), **Move size** (forecast), **Trend align / HTF** (structure), **Triggers** (the price levels that confirm).
- Use the "Filter" modes to suppress signals against regime or higher-timeframe structure, or leave them as badges and judge manually.
- The advanced rows show per-type follow-through statistics (hit rate, average favorable and adverse excursion in ATR) and an early-vs-late history split as a coarse robustness check. **These are in-sample descriptive statistics, not a backtest.** A companion strategy script with identical logic is available for proper backtesting with costs.
- Alerts: per-signal dynamic alert with all values (webhook-ready), plus static conditions for expiry signals, releases, critical pressure, and vol shocks.
## Originality
The pressure blend (compression x vol-dislocation x basis tension x convexity x inefficiency, percent-rank normalized), the variance-ratio regime gate applied to breakout qualification, the compression-energy budget, and the per-type MFE/MAE statistics with an early/late split are original constructions written from first principles for this script. The only classical components used are public-domain building blocks (ATR, Bollinger/Keltner-style compression logic via ATR percentile, Ichimoku cloud bias as a trend filter, Kaufman efficiency ratio), each justified above.
## Limitations (please read)
- Dealer-positioning effects (often discussed as gamma/vanna/charm) are **inferred from price, volatility and basis behavior**. This script does not and cannot read option-chain open interest. Labels such as "gamma blast" describe an expiry-session release pattern, not a measured dealer position.
- All on-panel statistics are computed on the loaded chart history and will differ across symbols, timeframes and history length.
- Higher-timeframe confluence uses closed HTF bars by default (no repaint); the current chart bar still forms in real time, as with any script.
- Expected-move figures are model estimates, not guarantees.
This script is for education and analysis. It is **not financial advice**; trade at your own risk and test before use.
## What this script does
VPRA estimates **when a market is loading energy for an outsized move, how large that move could be, and whether the current regime favors chasing or fading the breakout**. It condenses this into one on-chart verdict panel, directional signal markers, a regime ribbon, and a forecast of the expected move in ATR and points.
It works on **any symbol, any market, any timeframe**. A related volatility index and a companion symbol (the underlying if you chart a derivative, or vice versa) are optional inputs that sharpen the analysis; both can be disabled and the model renormalizes to price-only mode automatically.
## Why these components are combined (mashup justification)
Each module answers a question the others cannot, and the signal only fires when their answers agree. None of them is a stock indicator pasted alongside another — they are inputs to a single pressure model:
1. **Compression (ATR percentile)** answers *"is energy being stored?"* Quiet ranges precede expansion, but compression alone says nothing about direction or timing.
2. **Implied-vs-realized volatility dislocation** (optional vol index) answers *"is the options market mispricing the calm?"* A large gap between implied and realized volatility marks complacency or stress that compression alone cannot see.
3. **Basis tension** (optional companion symbol) answers *"is positioning leaning?"* Momentum in the derivative-to-underlying spread, and outright backwardation, reveal funding pressure and de-risking invisible in a single price series.
4. **Convexity and trend inefficiency** (return acceleration, efficiency ratio) answer *"is price behavior becoming unstable?"*
These four are blended into one **Pressure score (0–100)**, percent-ranked against its own history so thresholds adapt to every symbol and timeframe.
5. **A variance-ratio regime filter** answers *"will the break run or get faded?"* The ratio of k-bar to 1-bar return variance classifies the tape as mean-reverting (pinning) or trending (amplifying). Breakouts in a pinning regime are statistically more likely to fail, so the script can label or skip them.
6. **A multi-timeframe trend filter (Ichimoku cloud bias on the chart TF + three higher TFs)** answers *"is the release direction supported by structure?"* It grades signals rather than generating them. Higher-timeframe values are taken from **closed bars by default, so the confluence grade does not repaint**.
7. **Session, expiry, gap and event context** scale the expected-move forecast: an expiry-afternoon release during a volatility spike forecasts a larger move than a sleepy mid-session one.
Removing any module degrades a specific, named capability — that is the test the combination was built to pass.
## How a signal is generated
A marker prints only when **all** of the following align: pressure has reached a high percentile of its own history within a short lookback ("loaded"), the current bar shows a genuine range expansion ("release"), the condition persists for a confirmation bar count, a debounce gap has passed, and (optionally) the regime and trend filters pass. Direction is scored from **trigger-break** (close beyond the prior N-bar extreme), **close location** within the bar, and short momentum.
Marker color encodes the inferred event type: expiry-session releases, volatility-co-movement squeezes (price and vol index moving together — a short-covering tell), or plain expansions. The glow ring encodes how many higher timeframes agree. An ⓘ label stores a full diagnostic snapshot (pressure, regime, instability, basis, energy, session, expected move) in its tooltip for every signal.
## How to use it
- Apply to a liquid symbol; set "This chart is" to Derivative or Underlying, point the companion and volatility-index inputs at your market's related symbols (or disable them), and set your session hours and expiry weekday.
- Read the panel top-down: **Regime** (chase vs fade), **Pressure/Energy** (how loaded), **Move size** (forecast), **Trend align / HTF** (structure), **Triggers** (the price levels that confirm).
- Use the "Filter" modes to suppress signals against regime or higher-timeframe structure, or leave them as badges and judge manually.
- The advanced rows show per-type follow-through statistics (hit rate, average favorable and adverse excursion in ATR) and an early-vs-late history split as a coarse robustness check. **These are in-sample descriptive statistics, not a backtest.** A companion strategy script with identical logic is available for proper backtesting with costs.
- Alerts: per-signal dynamic alert with all values (webhook-ready), plus static conditions for expiry signals, releases, critical pressure, and vol shocks.
## Originality
The pressure blend (compression x vol-dislocation x basis tension x convexity x inefficiency, percent-rank normalized), the variance-ratio regime gate applied to breakout qualification, the compression-energy budget, and the per-type MFE/MAE statistics with an early/late split are original constructions written from first principles for this script. The only classical components used are public-domain building blocks (ATR, Bollinger/Keltner-style compression logic via ATR percentile, Ichimoku cloud bias as a trend filter, Kaufman efficiency ratio), each justified above.
## Limitations (please read)
- Dealer-positioning effects (often discussed as gamma/vanna/charm) are **inferred from price, volatility and basis behavior**. This script does not and cannot read option-chain open interest. Labels such as "gamma blast" describe an expiry-session release pattern, not a measured dealer position.
- All on-panel statistics are computed on the loaded chart history and will differ across symbols, timeframes and history length.
- Higher-timeframe confluence uses closed HTF bars by default (no repaint); the current chart bar still forms in real time, as with any script.
- Expected-move figures are model estimates, not guarantees.
This script is for education and analysis. It is **not financial advice**; trade at your own risk and test before use.
Informacje o Wersji
VPRA v2 — Path-dependent volatility forecastThis update adds a compact forecast of next-period realized volatility, built entirely from the price path (a reduced form of the Guyon & Lekeufack 2023 path-dependent volatility model: a leverage feature R1 and an activity feature sqrt(R2), each a fast+slow kernel blend of the confirmed, lagged returns, lightly calibrated to this chart's own realized vol). It is used to upgrade two pieces that were previously heuristic, and adds one trust gauge:
1) Sharper dislocation. The implied-vs-realized factor now compares the volatility index against the FORECAST of realized vol rather than the trailing realized vol. Implied-vs-expected is the variance-risk-premium reading; trailing realized lags and is symmetric.
2) Model-anchored expected move. The expected-move magnitude (expATR / expPts) is now anchored to the fitted forecast, converted to ATR units, and then modulated by pressure and the existing flow factors — instead of a fixed linear pressure slope. The expected move now widens and narrows with the model's own volatility level.
3) Trust gauge (toggle). A rolling R-squared of the forecast versus realized vol shows how much of realized-vol variance the price path explains on this symbol. Low fit ("weak") flags a structural break where the vol-based reads deserve less weight. It is informational and does not block signals.
Design note: the forecast is deliberately NOT added as another term in the pressure blend — that would double-count the compression / vol-level signal the existing factors already carry. It is used only where it fills a gap (the dislocation comparison and the expected-move magnitude) and as an independent trust gauge. Turning the forecast off restores exact v1 behaviour. The forecast is price-only, so (2) and (3) work even on assets without a volatility index; (1) requires the volatility index.
New inputs (group "Path-dependent vol forecast"): master on/off, fast/slow kernel lengths, fast-vs-slow weight, calibration window, and a toggle for the fit gauge. New panel rows show the vol forecast (against VIX when present) and the fit gauge; new Data Window fields export the forecast (annualized %), the forecast move in ATR units, and the fit %.
Limitations: the forecast is a reduced form (no upside-convexity, HAR persistence, or power-law tail of the full model) and forecasts a smoothed realized vol; it is itself uncertain, so trust it more when the fit gauge is high. As before, dealer-flow effects are inferred from price/vol/basis, all statistics are in-sample, and nothing here is financial advice.
Informacje o Wersji
VPRA·5HTF — Update: faster load, sharper regime, bug fix⚡ Faster loading
The 5 higher-timeframe requests and the 3 Ichimoku requests are now genuinely gated — turning a feature off actually skips its data requests (previously they always ran). Disable the HTF ladder and you drop from ~7 to 2 requests.
Ichimoku confluence now defaults OFF (it added 3 HTF requests); re-enable under Confluence any time.
Added an internal bar cap so the engine computes recent history only.
📊 Sharper regime
The variance-ratio regime now requires statistical significance (Lo–MacKinlay z-test) before calling AMPLIFY or PIN — it sits on NEUTRAL when the read is just noise, cutting false regime flips. Toggleable, with a tunable z-threshold under Regime.
🐛 Bug fix
Fixed Energy occasionally showing NaN (an unguarded accumulator that could propagate a bad value). Hardened it and the follow-through stat accumulators so they stay valid.
Note: two defaults changed — Ichimoku confluence is now off, and the regime sits NEUTRAL more often (that's the significance guard, not a fault). Both are one click to restore. The path-vol fit gauge reading "weak" on low timeframes is expected — the forecast fits better on 15m+.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.