OPEN-SOURCE SCRIPT
Statistical Price Deviation Index (MAD/VWMA)

SPDI is a statistical oscillator designed to detect potential price reversal zones by measuring how far price deviates from its typical behavior within a defined rolling window.
Instead of using momentum or moving averages like traditional indicators, SPDI applies robust statistics - a rolling median and Mean Absolute Deviation (MAD) - to calculate a normalized measure of price displacement. This normalization keeps the output bounded (from −1 to +1 by default), producing a stable and consistent oscillator that adapts to changing volatility conditions.
The second line in SPDI uses a Volume-Weighted Moving Average (VWMA) instead of a simple price median. This creates a complementary oscillator showing statistically weighted deviations based on traded volume. When both oscillators align in their extremes, strong confluence reversal signals are generated.
How It Works
How to Use
Settings Tips
Summary:
SPDI transforms raw price and volume data into a statistically bounded deviation index. When both Price MAD and VWMA Disp reach joint extremes, it highlights probable market turning points - offering traders a clean, data-driven way to spot potential reversals ahead of time.
Instead of using momentum or moving averages like traditional indicators, SPDI applies robust statistics - a rolling median and Mean Absolute Deviation (MAD) - to calculate a normalized measure of price displacement. This normalization keeps the output bounded (from −1 to +1 by default), producing a stable and consistent oscillator that adapts to changing volatility conditions.
The second line in SPDI uses a Volume-Weighted Moving Average (VWMA) instead of a simple price median. This creates a complementary oscillator showing statistically weighted deviations based on traded volume. When both oscillators align in their extremes, strong confluence reversal signals are generated.
How It Works
- For each bar, SPDI calculates the median price of the last N bars (default 100).
- It then measures how far the current bar’s midpoint deviates from that rolling median.
- The Mean Absolute Deviation (MAD) of those distances defines a “normal” range of fluctuation.
- The deviation is normalized and compressed via a tanh mapping, keeping the oscillator in fixed boundaries (−1 to +1).
- The same logic is applied to the VWMA line to gauge volume-weighted deviations.
How to Use
- The blue line (Price MAD) represents pure price deviation.
- The green line (VWMA Disp) shows the volume-weighted deviation.
- Overbought (red) zones indicate statistically extreme upward deviation -> potential short-term overextension.
- Oversold (green) zones indicate statistically extreme downward deviation -> potential rebound area.
- Confluence signals (both lines hitting the same extreme) often mark strong reversal points.
Settings Tips
- Lookback length controls how much historical data defines “normal” behavior. Larger = smoother, smaller = more sensitive.
- Smoothing (RMA length) can reduce noise without changing the overall statistical logic.
- Output scale can be set to either −1..+1 or 0..100, depending on your visual preference.
- Alerts and color fills are fully customizable in the Style tab.
Summary:
SPDI transforms raw price and volume data into a statistically bounded deviation index. When both Price MAD and VWMA Disp reach joint extremes, it highlights probable market turning points - offering traders a clean, data-driven way to spot potential reversals ahead of time.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.