OPEN-SOURCE SCRIPT

Dynamic MAs Zscore | Lyro RS

413
The Dynamic MAs Zscore is an adaptive momentum and valuation oscillator built around advanced moving averages and statistical Z-Score normalization. By combining a wide selection of moving average types with dynamic deviation bands, this indicator delivers clear insights into trend strength, directional bias, and relative valuation — all in a clean, visually intuitive format.


━━━━━━━━━━━━━━━
Key Features
━━━━━━━━━━━━━━━


  1. Dynamic Moving Average Engine
    Applies one of 12 selectable moving average types (SMA, EMA, WMA, VWMA, HMA, ALMA, TEMA, etc.) to the chosen source. This allows fine-tuning between responsiveness and smoothness depending on market conditions.

  2. Z-Score Normalization
    Transforms the selected moving average into a standardized Z-Score:
    (MA − mean) / standard deviation
    This normalization makes momentum strength comparable across assets and timeframes.

  3. Adaptive Deviation Bands
    Upper and lower bands are derived from the rolling standard deviation of the Z-Score:
    Custom band length
    Independent positive and negative multipliers

    These bands dynamically expand and contract with volatility.

  4. Dual Signal ModesTrend Mode – Focuses on directional continuation. Color changes and signals occur when Z-Score breaks above or below deviation bands.
    Valuation Mode – Highlights relative overvaluation and undervaluation using a gradient color scale and predefined value zones.
  5. Advanced Visual System
    Includes bold layered plots, gradient fills, background shading, and candle/bar coloring to clearly reflect current market state.

  6. Custom Color Palettes
    Choose from multiple preset themes (Classic, Mystic, Accented, Royal) or define your own bullish and bearish colors.



━━━━━━━━━━━━━━━
How It Works
━━━━━━━━━━━━━━━


  1. MA Calculation – The selected moving average type is applied to the chosen price source.

  2. Z-Score Computation – The MA is normalized over a user-defined lookback period to quantify deviation from its mean.

  3. Band Construction – Standard deviation of the Z-Score is calculated over the band length and scaled by positive/negative multipliers.

  4. Mode-Dependent Logic
    • Trend Mode – Breaks above the upper band signal bullish momentum; breaks below the lower band signal bearish momentum.
    • Valuation Mode – A gradient reflects relative valuation from undervalued to overvalued, with background highlights at extreme Z-Score levels.


snapshot

━━━━━━━━━━━━━━━
Signal Interpretation
━━━━━━━━━━━━━━━


  • Trend Confirmation
    In Trend Mode, sustained moves beyond deviation bands indicate strong directional bias.

  • Momentum Strength
    The distance of the Z-Score from zero reflects the intensity of trend momentum.

  • Relative Valuation
    In Valuation Mode, deep negative Z-Scores suggest undervaluation, while high positive Z-Scores suggest overvaluation.

  • Visual Clarity
    Bar and candle coloring aligned with oscillator state allows for rapid assessment of market conditions.


snapshot

━━━━━━━━━━━━━━━
Customization
━━━━━━━━━━━━━━━


  • Adjust MA type and length to balance speed vs. smoothness.
  • Modify Z-Score length to control sensitivity.
  • Tune band length and multipliers for volatility adaptation.
  • Switch between Trend and Valuation modes depending on strategy.
  • Personalize visuals using preset or custom color palettes.



━━━━━━━━━━━━━━━
Alerts
━━━━━━━━━━━━━━━


  • Bullish condition when Z-Score > 0
  • Bearish condition when Z-Score < 0
  • Overvalued and undervalued valuation alerts



⚠️ Disclaimer
This indicator is intended for technical analysis and educational purposes only. It does not guarantee profitable outcomes and should be used alongside other tools, confirmation methods, and sound risk management. The author is not responsible for any financial decisions made using this indicator.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.