OPEN-SOURCE SCRIPT
Mean Deviation Trail | Lyro RS

Introduction:
The Mean Deviation Trail (MDT) is an adaptive trend-following overlay that pairs Mean Absolute Deviation (MAD) volatility normalization with a signed, smoothed deviation signal to produce a dynamic, self-adjusting trail. Instead of relying on a fixed-width channel, MDT continuously measures how far — and in which direction — price departs from its mean, then modulates the trail width in real time. The outcome is a trail that tightens during strong directional regimes and widens during low-momentum or choppy phases.
How It Works
Key Features
Signal Interpretation
Recommended Settings
⚠️ Disclaimer
This indicator is for educational and informational purposes only. It does not constitute financial, investment, or trading advice. Past performance is not indicative of future results. Always combine with price action, proper risk management, and additional analysis.
The Mean Deviation Trail (MDT) is an adaptive trend-following overlay that pairs Mean Absolute Deviation (MAD) volatility normalization with a signed, smoothed deviation signal to produce a dynamic, self-adjusting trail. Instead of relying on a fixed-width channel, MDT continuously measures how far — and in which direction — price departs from its mean, then modulates the trail width in real time. The outcome is a trail that tightens during strong directional regimes and widens during low-momentum or choppy phases.
How It Works
- Deviation Engine — All calculations are anchored to an EMA of the source. From this anchor, the signed normalized deviation is computed:
Deviation Raw = (Price − EMA) / MAD
This captures both the direction and the relative magnitude of price displacement. A user-selectable smoothing MA (16 types) is then applied to filter noise from the raw signal. - MAD Volatility Normalizer — Mean Absolute Deviation is calculated across a rolling lookback:
MAD = Σ |Price − EMA| / Length
Unlike standard deviation, MAD is not inflated by squared error terms, making it more resistant to outlier spikes and producing a smoother volatility anchor. - Adaptive Trail Width — The smoothed deviation signal is scaled against its 80-bar peak to produce sigNorm (a value between 0 and 1). This drives the multiplier between two user-defined extremes:
- Strong deviation → multiplier approaches the Tight value → trail hugs price.
- Weak deviation → multiplier approaches the Wide value → trail drifts away.
Multiplier = Wide − sigNorm × (Wide − Tight)
Bandwidth = MAD × Multiplier - Trail & Outer Band — The trail sits below price in uptrends and above price in downtrends, offset from the EMA by the adaptive bandwidth. An optional outer band plots at half-bandwidth on the opposite side, useful as a soft confirmation level.
- Trend State — Trend flips when the smoothed deviation crosses zero. Each flip prints a Long or Short label and resets the trail on the opposite side of price.
Key Features
- 16 Smoothing MA Types — SMA, EMA, WMA, VWMA, DEMA, TEMA, RMA, HMA, LSMA, SMMA, ALMA, ZLSMA, FRAMA, KAMA, JMA, T3.
- Adaptive Trail Width — Tight in high-deviation regimes, wide when momentum decays.
- Optional Outer Band — A half-width band on the opposite side for additional context.
- Gradient & Trend Color Modes — Gradient scales color intensity with deviation strength; Trend applies flat directional coloring.
- Colored Candles & Bar Color — Full chart integration with signal-aware candle coloring.
- Long / Short Signal Labels — Printed at trend crossovers with 𝓛𝓸𝓷𝓰 / 𝓢𝓱𝓸𝓻𝓽 labels.
- Color Palettes — Classic, Mystic, Accented, Royal, or fully custom.
- Status Table — Displays live Trend direction and Strength (Weak / Moderate / Strong).
- Alerts — Confirmed Bullish and Bearish alert conditions included.
Signal Interpretation
- A Long signal (𝓛𝓸𝓷𝓰 label, below bar) fires when the smoothed deviation crosses above zero — price is pulling away from the mean to the upside and the trail flips below price.
- A Short signal (𝓢𝓱𝓸𝓻𝓽 label, above bar) fires when the smoothed deviation crosses below zero — price is pulling away from the mean to the downside and the trail flips above price.
- Strength = Strong indicates the deviation signal is near its recent peak — trend is mature and the trail is tight. Weak indicates a fading or compressing regime — the trail loosens, and continuation should be treated with more caution.
Recommended Settings
- Long-Term Investing: 1D, MA Length 40, Smoothing 20, MAD 14
- Swing Trading: 4h, default settings
- Intraday Trading: 15m, MA Length 20, Smoothing 9, MAD 7, Tight 0.4, Wide 1.8
⚠️ Disclaimer
This indicator is for educational and informational purposes only. It does not constitute financial, investment, or trading advice. Past performance is not indicative of future results. Always combine with price action, proper risk management, and additional analysis.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
Get access to our private indicators: whop.com/lyro-rs
Join our community: discord.gg/kcEBMWaFjS
Join our community: discord.gg/kcEBMWaFjS
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
Get access to our private indicators: whop.com/lyro-rs
Join our community: discord.gg/kcEBMWaFjS
Join our community: discord.gg/kcEBMWaFjS
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.