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.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.