OPEN-SOURCE SCRIPT
MA Z-Score Deviation

A valuation oscillator that measures how far price has stretched from its statistical fair value defined here as its moving average, expressed as a standardized score rather than raw price units.
How it works
Base: A moving average (SMA, EMA, or WMA) serves as the reference "fair value" line. Deviation from this baseline is calculated as a log ratio (log(price / MA)) rather than a simple price difference, so the reading stays comparable across different price levels and time periods: a 5% premium or discount reads the same whether the instrument is at $10 or $500.
Standardization: the deviation is divided by its own rolling dispersion to produce a score that expresses how rich or cheap price is relative to its typical range, not just in absolute terms.
Two dispersion methods are available:
Standard Deviation: the classical measure of typical variability.
MAD: a median-based measure that's more resistant to distortion from one-off outlier bars.
Blend: a weighted combination of both, adjustable via the MAD Weight input.
Display scaling: the score is passed through a bounded transform for cleaner visual scaling on the chart, while the underlying valuation ranking is preserved.
Inputs
Source & MA type (SMA/EMA/WMA) and length
Lookback length for the dispersion calculation, independent from the MA length, letting you compare long-term fair value against recent volatility conditions
Dispersion method (Stdev / MAD / Blend) and blend weight
Display scaling factor
Reading the indicator
Positive values indicate price is trading at a premium to its baseline; negative values indicate a discount.
Values beyond ±2 suggest a notable premium/discount relative to recent conditions; beyond ±3 suggests a substantial one.
Because the baseline is statistical rather than fixed, the "fair value" and its bands adjust automatically as market conditions evolve.
Notes / limitations
This measures statistical richness/cheapness relative to a moving average, not intrinsic or fundamental value; it's a technical valuation lens, not a fundamental one.
Financial return distributions have fatter tails than a normal distribution assumes, so extreme readings can occur more frequently than the underlying statistical model implies; treat scores as relative positioning, not precise probabilities.
Alerts trigger only on confirmed bar closes to avoid firing on intrabar noise.
How it works
Base: A moving average (SMA, EMA, or WMA) serves as the reference "fair value" line. Deviation from this baseline is calculated as a log ratio (log(price / MA)) rather than a simple price difference, so the reading stays comparable across different price levels and time periods: a 5% premium or discount reads the same whether the instrument is at $10 or $500.
Standardization: the deviation is divided by its own rolling dispersion to produce a score that expresses how rich or cheap price is relative to its typical range, not just in absolute terms.
Two dispersion methods are available:
Standard Deviation: the classical measure of typical variability.
MAD: a median-based measure that's more resistant to distortion from one-off outlier bars.
Blend: a weighted combination of both, adjustable via the MAD Weight input.
Display scaling: the score is passed through a bounded transform for cleaner visual scaling on the chart, while the underlying valuation ranking is preserved.
Inputs
Source & MA type (SMA/EMA/WMA) and length
Lookback length for the dispersion calculation, independent from the MA length, letting you compare long-term fair value against recent volatility conditions
Dispersion method (Stdev / MAD / Blend) and blend weight
Display scaling factor
Reading the indicator
Positive values indicate price is trading at a premium to its baseline; negative values indicate a discount.
Values beyond ±2 suggest a notable premium/discount relative to recent conditions; beyond ±3 suggests a substantial one.
Because the baseline is statistical rather than fixed, the "fair value" and its bands adjust automatically as market conditions evolve.
Notes / limitations
This measures statistical richness/cheapness relative to a moving average, not intrinsic or fundamental value; it's a technical valuation lens, not a fundamental one.
Financial return distributions have fatter tails than a normal distribution assumes, so extreme readings can occur more frequently than the underlying statistical model implies; treat scores as relative positioning, not precise probabilities.
Alerts trigger only on confirmed bar closes to avoid firing on intrabar noise.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。