OPEN-SOURCE SCRIPT

MA Distance Stretch & Mean Reversion Levels

382
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.

Отказ от ответственности

Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.