OPEN-SOURCE SCRIPT
已更新 MA200 Deviation Percentile

200-Day MA Deviation with Dynamic Thresholds
OVERVIEW
This indicator measures price deviation from the 200-day moving average as a percentage, with dynamically calculated overbought/oversold thresholds based on historical percentiles.
Best suited for broad market indices (SPY, QQQ, IWM, etc.) where the 200-day MA serves as a reliable long-term trend indicator. Individual stocks may exhibit more erratic behavior around this level.
CALCULATION
Deviation (%) = (Close - 200MA) / 200MA x 100
Dynamic thresholds are derived from actual historical distribution rather than assuming normal distribution:
- Overbought threshold = 97.5th percentile of historical deviations
- Oversold threshold = 2.5th percentile of historical deviations
SETTINGS
MA Length (default: 200)
Moving average period.
Lookback Period (default: 1260)
Historical window for threshold calculation. 1260 bars approximates 5 years of daily data.
Threshold Percentile (default: 5%)
Two-tailed threshold. 5% places overbought/oversold boundaries at the 97.5th and 2.5th percentiles respectively.
INTERPRETATION
Deviation Value
- Positive: Price trading above 200MA
- Negative: Price trading below 200MA
- Magnitude indicates extent of deviation
Percentile Ranking (0-100%)
- Shows where current deviation ranks historically
- Above 90%: Historically elevated
- Below 10%: Historically depressed
Dynamic Threshold Lines
- Red line: Upper boundary based on historical distribution
- Green line: Lower boundary based on historical distribution
- These adapt automatically to each asset's volatility characteristics
APPLICATION
Mean Reversion
Extreme deviations tend to normalize over time. When deviation exceeds dynamic thresholds, probability of mean reversion increases.
Trend Assessment
Sustained positive/negative deviation confirms trend direction. Zero-line crossovers may signal trend changes.
NOTES
- Optimized for daily timeframe on market indices
- Requires sufficient historical data (minimum equal to lookback period)
- Extreme readings do not guarantee immediate reversals
- Use in conjunction with other analysis methods
OVERVIEW
This indicator measures price deviation from the 200-day moving average as a percentage, with dynamically calculated overbought/oversold thresholds based on historical percentiles.
Best suited for broad market indices (SPY, QQQ, IWM, etc.) where the 200-day MA serves as a reliable long-term trend indicator. Individual stocks may exhibit more erratic behavior around this level.
CALCULATION
Deviation (%) = (Close - 200MA) / 200MA x 100
Dynamic thresholds are derived from actual historical distribution rather than assuming normal distribution:
- Overbought threshold = 97.5th percentile of historical deviations
- Oversold threshold = 2.5th percentile of historical deviations
SETTINGS
MA Length (default: 200)
Moving average period.
Lookback Period (default: 1260)
Historical window for threshold calculation. 1260 bars approximates 5 years of daily data.
Threshold Percentile (default: 5%)
Two-tailed threshold. 5% places overbought/oversold boundaries at the 97.5th and 2.5th percentiles respectively.
INTERPRETATION
Deviation Value
- Positive: Price trading above 200MA
- Negative: Price trading below 200MA
- Magnitude indicates extent of deviation
Percentile Ranking (0-100%)
- Shows where current deviation ranks historically
- Above 90%: Historically elevated
- Below 10%: Historically depressed
Dynamic Threshold Lines
- Red line: Upper boundary based on historical distribution
- Green line: Lower boundary based on historical distribution
- These adapt automatically to each asset's volatility characteristics
APPLICATION
Mean Reversion
Extreme deviations tend to normalize over time. When deviation exceeds dynamic thresholds, probability of mean reversion increases.
Trend Assessment
Sustained positive/negative deviation confirms trend direction. Zero-line crossovers may signal trend changes.
NOTES
- Optimized for daily timeframe on market indices
- Requires sufficient historical data (minimum equal to lookback period)
- Extreme readings do not guarantee immediate reversals
- Use in conjunction with other analysis methods
版本注释
MA200 Deviation PercentileOVERVIEW
This indicator calculates how far the current price deviates from its 200-day moving average, then ranks this deviation against the past 10 years of historical data as a percentile (0-100%).
Best suited for broad market indices (SPY, QQQ, IWM, etc.) where the 200-day MA serves as a reliable long-term trend indicator.
CALCULATION
1. Deviation (%) = (Close - 200MA) / 200MA x 100
2. Percentile = Rank of current deviation within rolling 10-year historical window
Example:
- Percentile 95%: Current deviation is higher than 95% of readings over the past 10 years
- Percentile 5%: Current deviation is lower than 95% of readings over the past 10 years
SETTINGS
MA Length (default: 200)
Moving average period.
Lookback Period (default: 2520)
Rolling window for percentile calculation. 2520 bars approximates 10 years of daily data.
Overbought Level (default: 95%)
Upper threshold for extreme readings.
Oversold Level (default: 5%)
Lower threshold for extreme readings.
INTERPRETATION
- 95-100%: Historically extreme overbought
- 50%: Median deviation level
- 0-5%: Historically extreme oversold
When percentile reaches extreme levels (above 95% or below 5%), mean reversion probability increases.
VISUAL ELEMENTS
- Blue line: Percentile ranking (0-100%)
- Red dashed line: Overbought threshold
- Green dashed line: Oversold threshold
- Gray line: 50% median
- Background highlight: Indicates extreme zones
- Triangle markers: Signal entry into extreme zones
NOTES
- Optimized for daily timeframe on market indices
- Requires sufficient historical data (minimum 10 years recommended)
- Extreme readings indicate statistical rarity, not guaranteed reversals
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。