OPEN-SOURCE SCRIPT

Rolling Z Score Reversion Map [Pineify]

3 353
Rolling Z Score Reversion Map [Pineify]

Overview
This map keeps rolling price Z-score visible while separating reversion-eligible extremes from trend-aligned extremes. It describes context; it does not forecast returns or issue trades.

Problem Definition
Z-score measures distance from a rolling mean in deviation units. Fixed lines such as +2 and -2 treat every extreme alike. That fails when the mean moves: positive Z can persist with a rising mean, so a contrarian reading confuses extension with disequilibrium. The script preserves raw Z and asks separately whether aligned trend and range pressure should withhold a reversion watch.

Design Rationale
Raw Z remains unchanged so its units stay interpretable. Mean slope is expressed as ATR per bar for cross-market comparison. ATR uses a prior-only percentile to avoid fixed price units and candidate self-ranking. Sign alignment isolates positive deviation with rising mean and its negative mirror. High ATR rank adds pressure but cannot dominate alone. A finite closed-bar watch preserves event order; permanent extreme marks would duplicate events. Lag and confirmation delay are accepted for auditable states.

Key Features
  • Raw Z-score with symmetric rails.
  • ATR-normalized slope, prior-only ATR rank, and direction gate.
  • Confirmed watch with mean, pressure, data, and time exits.
  • Optional visuals, table, and two alerts.


How It Works
The script computes a rolling mean and deviation of closes. Raw Z is their price difference divided by deviation; a near-zero denominator returns no value.

ATR defines range scale. Its percentile is a midrank against N prior ATR values: lower samples vote one and ties half. Current ATR is excluded. Mean change over the slope span is divided by ATR and bar count to obtain ATR per bar.

The gate tests whether Z and slope share a sign. Pressure combines 65% aligned trend strength, 20% upper-half ATR expansion, and 15% trend-volatility interaction, bounded from zero to one. An extreme qualifies when absolute Z reaches its rail and pressure stays below the gate.

A newly qualified close freezes watch side and entry Z. The watch ends on a crossing of the evolving mean, expiry, invalid data, or an invalidation-rail extreme with excessive pressure. A crossing is only observed, not caused. Warm-up covers all windows and rank history. Live colors can change; watches, markers, and alerts update on confirmed bars.

How Multiple Indicators Work Together
The components form one filter. Z supplies distance but not reference motion. ATR-normalized slope supplies motion; sign alignment relates it to the deviation. Prior ATR rank adds portable range context. Together they decide whether an extreme starts a watch. Without slope, the fixed-threshold failure returns; without ATR, calm and expansion are alike; without the watch, event chronology disappears.

Trading Ideas and Insights
Use the map to organize observation, not assume reversal. Cyan means pressure is below the gate and an extreme can start a confirmed watch. Orange means the same raw distance has stronger continuation context, so a contrarian label is withheld. A gold zero-axis marker records a later mean crossing. Compare states to find where fixed Z thresholds misdescribe context.

Unique Aspects
The contribution is separating measurement from interpretation. Many filters rescale an oscillator, preventing comparison with ordinary Z rails. Here raw distance stays intact while a bounded, direction-sensitive, range-relative gate classifies events. The watch preserves sequence: qualification occurs first; later bars cross the evolving mean or invalidate. No result is moved backward and no probability is implied.

How to Use
After warm-up, read height as raw Z and color as context. Cyan marks a candidate or active watch, orange a higher-pressure extreme, and gray a balanced or unavailable state. Diamonds and alerts mark confirmed entry. A zero circle records a watched crossing; an orange cross records invalidation. Use 15-minute to weekly charts and Once Per Bar Close alerts. These are states, not trade instructions.

Customization
Z window sets reference horizon; Extreme threshold sets event distance. ATR window and rank length set range context and history needs. Slope span smooths motion; Full trend pressure maps ATR-per-bar slope to full strength. Lower Maximum pressure tightens qualification. Invalidation Z and Maximum watch bars bound observation life. Visual layers can be disabled independently while raw Z and rails remain. Colors support varied themes.

Assumptions and Limitations
Rolling statistics change as samples enter and leave; Z implies neither normality nor stationarity. ATR rank is empirical, not probability, and needs complete history. Weights are design choices, not optimized constants. Slope lags; gaps can outrun it. The watch targets an evolving mean, not the entry mean. Live visuals are provisional, and confirmed events still depend on feed history. Inputs, adjustments, and synthetic charts can change results. Execution, costs, sizing, news, structure, and future returns are outside scope. Pineify checks syntax, not market behavior.

Conclusion
The map adds auditable context without changing Z-score units. Distance remains distance; trend, volatility, and watch state change only its label. Keep lag, sensitivity, and scope explicit.

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.