Mean Deviation Trail | Lyro RSIntroduction:
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.
Indicador Pine Script®






















