OPEN-SOURCE SCRIPT

Z-Score V2

119
Z-Score Reversal Indicator for TradingView
Catch Overextended Trends & Potential Reversals Using Statistical Z-Scores
📌 Overview

This indicator calculates the Z-score of price movements, helping traders identify overbought and oversold conditions based on standard deviations from the mean.

Plots the Z-score (forest green line) to visualize momentum strength.

Key levels at ±1, ±2, ±3 standard deviations (dashed white lines) highlight potential reversal zones.
Customizable lookback period to adjust sensitivity.

Ideal for:
Mean-reversion strategies
Trend exhaustion detection
Breakout confirmation

📊 How It Works (The Math Behind It)
The Z-score measures how far the current price is from its mean, normalized by standard deviation.
🔹 Formula:

Z = (X − μ) / σ
X = Current price (or selected source)
μ = Simple Moving Average (SMA) over the lookback period
σ = Standard deviation over the lookback period

🎯 Trading Applications

Reversal Trading (Mean Reversion):
Short near +2 or +3 (expecting a pullback toward the mean).
Long near -2 or -3 (expecting a bounce toward the mean).

Trend Continuation (Breakout Confirmation):
If price breaks above +2 or +3, momentum may continue further.
If price breaks below -2 or -3, downtrend may accelerate.

Divergence Detection:
If price makes a new high but Z-score fails to reach prior highs, weakening momentum (bearish divergence).
If price makes a new low but Z-score fails to reach prior lows, potential bullish reversal.

⚙️ Customization Options

Adjustable Lookback Period – Modify sensitivity (shorter = more responsive, longer = smoother).

Source Selection – Apply to close, open, hl2, etc.

Clean Visuals – Plotlines do not distort scaling (only Z-score affects autofit).

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.