OPEN-SOURCE SCRIPT
SPMA Trend | NAL

1. Overview
SPMA Trend | NAL is an adaptive trend and volatility framework built around the Shock Percentile Moving Average.
Unlike a conventional moving average that continuously follows price, the SPMA selectively updates when the current price change ranks above a configurable percentile of recent returns. This creates an event-driven baseline that places greater emphasis on stronger positive price shocks while holding its previous value during lower-ranked movement.
SPMA Trend expands this concept with adaptive volatility bands, asymmetric shock modeling, empirical quantile boundaries, and optional slope confirmation to form a complete directional regime model.
2. Core Calculation
The SPMA begins by ranking the current price change against its recent historical distribution.
Pine Script®
When the percentile gate is satisfied, the baseline updates to the current EMA value. Otherwise, it retains its previous level.
Pine Script®
This produces a persistent baseline whose movement is concentrated around stronger ranked price events rather than every fluctuation in price.
3. Adaptive Volatility Framework
SPMA Trend surrounds the baseline with a configurable volatility structure.
Five volatility models are available:
Standard Deviation — measures dispersion around the mean.
ATR — measures price-range volatility.
Mean Absolute Deviation — measures average absolute dispersion.
Median Absolute Deviation — provides a more robust measure of dispersion with reduced sensitivity to extreme observations.
Quantile — constructs the upper and lower boundaries from the empirical distribution of historical price deviations from the SPMA.
The Quantile model is inherently asymmetric. Positive and negative residuals are evaluated separately, allowing each side of the structure to reflect its own historical distribution.
Pine Script®
For the conventional volatility models, an optional asymmetric mode analyzes positive and negative log-return shocks independently. This allows upper and lower volatility expansion to respond differently when the distribution of market shocks becomes unbalanced.
The resulting volatility estimate is applied around the SPMA to create the final adaptive boundaries.
Pine Script®
4. Signal Structure
The bullish regime is deliberately selective.
Price must break above the upper volatility boundary while the SPMA itself is rising. When enabled, the percentage slope of the SPMA must also exceed the configured slope threshold.
Pine Script®
A bearish regime is established when price moves below the lower adaptive boundary.
Pine Script®
Between qualifying transitions, the previous directional state is retained. This converts individual volatility-band events into a persistent trend regime rather than a sequence of isolated crossover signals.
5. Key Features
6. Use
SPMA Trend is designed as a specialized trend-regime component within a broader systematic framework.
The indicator combines three distinct layers of information: the significance of recent price movement determines when the baseline adapts, the volatility model determines how far price must expand from that structure, and the optional slope gate measures whether the underlying SPMA is developing with sufficient positive directional strength.
This creates a framework centered on identifying meaningful expansion away from an event-driven price structure rather than responding to every short-term movement.
Its primary value is as a distinct structural layer within a complete strategy architecture, where shock significance, volatility expansion, and directional development can be integrated with other independent forms of market information.
SPMA Trend | NAL is an adaptive trend and volatility framework built around the Shock Percentile Moving Average.
Unlike a conventional moving average that continuously follows price, the SPMA selectively updates when the current price change ranks above a configurable percentile of recent returns. This creates an event-driven baseline that places greater emphasis on stronger positive price shocks while holding its previous value during lower-ranked movement.
SPMA Trend expands this concept with adaptive volatility bands, asymmetric shock modeling, empirical quantile boundaries, and optional slope confirmation to form a complete directional regime model.
2. Core Calculation
The SPMA begins by ranking the current price change against its recent historical distribution.
When the percentile gate is satisfied, the baseline updates to the current EMA value. Otherwise, it retains its previous level.
This produces a persistent baseline whose movement is concentrated around stronger ranked price events rather than every fluctuation in price.
3. Adaptive Volatility Framework
SPMA Trend surrounds the baseline with a configurable volatility structure.
Five volatility models are available:
Standard Deviation — measures dispersion around the mean.
ATR — measures price-range volatility.
Mean Absolute Deviation — measures average absolute dispersion.
Median Absolute Deviation — provides a more robust measure of dispersion with reduced sensitivity to extreme observations.
Quantile — constructs the upper and lower boundaries from the empirical distribution of historical price deviations from the SPMA.
The Quantile model is inherently asymmetric. Positive and negative residuals are evaluated separately, allowing each side of the structure to reflect its own historical distribution.
For the conventional volatility models, an optional asymmetric mode analyzes positive and negative log-return shocks independently. This allows upper and lower volatility expansion to respond differently when the distribution of market shocks becomes unbalanced.
The resulting volatility estimate is applied around the SPMA to create the final adaptive boundaries.
4. Signal Structure
The bullish regime is deliberately selective.
Price must break above the upper volatility boundary while the SPMA itself is rising. When enabled, the percentage slope of the SPMA must also exceed the configured slope threshold.
A bearish regime is established when price moves below the lower adaptive boundary.
Between qualifying transitions, the previous directional state is retained. This converts individual volatility-band events into a persistent trend regime rather than a sequence of isolated crossover signals.
5. Key Features
- Shock-percentile adaptive baseline.
- Event-driven rather than continuously updating trend structure.
- Five selectable volatility models.
- Mean and median absolute-deviation volatility.
- Empirical asymmetric residual quantiles.
- Optional positive/negative shock-adjusted volatility bands.
- Configurable SPMA slope confirmation.
- Persistent bullish and bearish regime states.
- Adaptive band, glow, fill, and candle visualization.
6. Use
SPMA Trend is designed as a specialized trend-regime component within a broader systematic framework.
The indicator combines three distinct layers of information: the significance of recent price movement determines when the baseline adapts, the volatility model determines how far price must expand from that structure, and the optional slope gate measures whether the underlying SPMA is developing with sufficient positive directional strength.
This creates a framework centered on identifying meaningful expansion away from an event-driven price structure rather than responding to every short-term movement.
Its primary value is as a distinct structural layer within a complete strategy architecture, where shock significance, volatility expansion, and directional development can be integrated with other independent forms of market information.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
🔵 Access our best trading & investing tools, get a 30-day free trial today: whop.com/nordic-alpha-lab/
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
🔵 Access our best trading & investing tools, get a 30-day free trial today: whop.com/nordic-alpha-lab/
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.