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.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source verรถffentlicht. Auf diese Weise kรถnnen nun auch andere Trader das Script rezensieren und die Funktionalitรคt รผberprรผfen. Vielen Dank an den Autor! Sie kรถnnen das Script kostenlos verwenden, aber eine Wiederverรถffentlichung des Codes unterliegt unseren Hausregeln.
Get access to our private indicators: whop.com/lyro-rs
Join our community: discord.gg/kcEBMWaFjS
Join our community: discord.gg/kcEBMWaFjS
Haftungsausschluss
Die Informationen und Verรถffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlรคgen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source verรถffentlicht. Auf diese Weise kรถnnen nun auch andere Trader das Script rezensieren und die Funktionalitรคt รผberprรผfen. Vielen Dank an den Autor! Sie kรถnnen das Script kostenlos verwenden, aber eine Wiederverรถffentlichung des Codes unterliegt unseren Hausregeln.
Get access to our private indicators: whop.com/lyro-rs
Join our community: discord.gg/kcEBMWaFjS
Join our community: discord.gg/kcEBMWaFjS
Haftungsausschluss
Die Informationen und Verรถffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlรคgen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.