OPEN-SOURCE SCRIPT
MA Distance Stretch & Mean Reversion Levels

Shows how far price is from the 50 and 200 MA, and whether that distance is normal or overstretched relative to the ticker's own history.
Most "distance from MA" tools give you a raw percentage and leave you to guess whether +23% is a lot. This one measures the rolling mean and standard deviation of that distance over a lookback, converts the current reading into a z‑score, and tells you in plain words where you are.
What you see
📐 % distance from each MA (optional $ distance)
📊 μ / σ — historic mean and standard deviation of that distance over the lookback
🎯 z‑score — how many σ price is from its normal distance
🚦 Status — Normal / Extended / OVERSTRETCHED, with direction arrow and colour‑coded row
📍 ±σ bands — dotted price levels at MA × (1 + μ ± kσ): the actual prices where the stretch would hit your threshold. Use them as mean‑reversion targets or as the level price must hold to stay extended
Settings
Group Setting Default
Averages Fast / Slow MA length 50 / 200
MA type SMA (or EMA)
Use last closed bar Off — excludes the live candle when on
Stretch Stats lookback 250 bars
Extended at 1.0σ
Overstretched at 2.0σ
Draw ±σ bands / band width On / 2.0σ
Display Show $ distance Off
Padding rows 1 — stacks the readout above other bottom‑left tables
Notes
Mean is rarely zero: a name in a long uptrend "normally" sits above its 200 MA, so the z‑score measures stretch against that baseline, not against the MA itself.
Lookback sets the regime. 250 bars on a daily chart ≈ one year; shorten it if you want the stats to reflect recent behaviour only.
Both rows show na until the chart has MA length + lookback bars of history.
All calculations run on every bar; the closed‑bar toggle only shifts what's displayed.
Works on any symbol and timeframe.
Most "distance from MA" tools give you a raw percentage and leave you to guess whether +23% is a lot. This one measures the rolling mean and standard deviation of that distance over a lookback, converts the current reading into a z‑score, and tells you in plain words where you are.
What you see
📐 % distance from each MA (optional $ distance)
📊 μ / σ — historic mean and standard deviation of that distance over the lookback
🎯 z‑score — how many σ price is from its normal distance
🚦 Status — Normal / Extended / OVERSTRETCHED, with direction arrow and colour‑coded row
📍 ±σ bands — dotted price levels at MA × (1 + μ ± kσ): the actual prices where the stretch would hit your threshold. Use them as mean‑reversion targets or as the level price must hold to stay extended
Settings
Group Setting Default
Averages Fast / Slow MA length 50 / 200
MA type SMA (or EMA)
Use last closed bar Off — excludes the live candle when on
Stretch Stats lookback 250 bars
Extended at 1.0σ
Overstretched at 2.0σ
Draw ±σ bands / band width On / 2.0σ
Display Show $ distance Off
Padding rows 1 — stacks the readout above other bottom‑left tables
Notes
Mean is rarely zero: a name in a long uptrend "normally" sits above its 200 MA, so the z‑score measures stretch against that baseline, not against the MA itself.
Lookback sets the regime. 250 bars on a daily chart ≈ one year; shorten it if you want the stats to reflect recent behaviour only.
Both rows show na until the chart has MA length + lookback bars of history.
All calculations run on every bar; the closed‑bar toggle only shifts what's displayed.
Works on any symbol and timeframe.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.