OPEN-SOURCE SCRIPT
Z-Score V2

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).
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).
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.
For quick access on a chart, add this script to your favorites — learn more here.
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.
For quick access on a chart, add this script to your favorites — learn more here.
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.