OPEN-SOURCE SCRIPT
SPMA Supertrend | NAL

SPMA Supertrend is a trend-following framework that replaces the conventional Supertrend center with a Shock Percentile Moving Average (SPMA).
Unlike a traditional moving average that updates on every bar, SPMA only accepts a new baseline value when the current one-bar return ranks sufficiently high relative to its recent distribution. When that percentile condition is not met, the baseline remains unchanged.
The result is an event-driven trend structure designed to respond selectively to meaningful upside price displacement rather than continuously following every movement in price.
1. Shock Percentile Moving Average
The SPMA begins by calculating the current one-bar price change and ranking that observation against its recent history:
Pine Script®
The percentile gate determines whether the underlying EMA is permitted to update.
Pine Script®
When the gate is satisfied, SPMA adopts the current EMA value. Otherwise, it preserves its previous level.
This creates a baseline whose evolution is determined by relative return significance rather than the passage of time alone.
Higher percentile settings make the model increasingly selective, while lower settings allow the baseline to update more frequently.
2. SPMA Supertrend
The SPMA is then used as the center of a conventional trailing-band Supertrend architecture.
Pine Script®
ATR defines the volatility distance around the event-driven baseline, while the trailing-band logic converts the structure into persistent bullish and bearish regimes.
This produces a hybrid model combining percentile-ranked price displacement, selective baseline updating, volatility normalization, and Supertrend state persistence.
Visuals & Interpretation
Only the active Supertrend boundary is displayed.
A gradient extends between the hidden SPMA baseline and the active Supertrend level, making the relationship between the event-driven baseline and current trend boundary visible without adding unnecessary chart clutter.
Candles are also colored according to the active regime.
Three visual presets are included:
Practical Application
SPMA Supertrend is designed for identifying directional market structure while reducing the influence of routine price movement on the underlying trend baseline.
The key distinction from a standard Supertrend is simple:
The volatility bands still respond continuously, but the underlying baseline only evolves when price movement is sufficiently significant relative to its recent distribution.
Users can independently control the baseline horizon, percentile-ranking window, percentile gate, ATR horizon, and Supertrend volatility multiplier.
Automated Alerts
Built-in alerts are included for both directional transitions:
For closed-bar confirmation, configure TradingView alerts to trigger Once Per Bar Close.
Unlike a traditional moving average that updates on every bar, SPMA only accepts a new baseline value when the current one-bar return ranks sufficiently high relative to its recent distribution. When that percentile condition is not met, the baseline remains unchanged.
The result is an event-driven trend structure designed to respond selectively to meaningful upside price displacement rather than continuously following every movement in price.
1. Shock Percentile Moving Average
The SPMA begins by calculating the current one-bar price change and ranking that observation against its recent history:
The percentile gate determines whether the underlying EMA is permitted to update.
When the gate is satisfied, SPMA adopts the current EMA value. Otherwise, it preserves its previous level.
This creates a baseline whose evolution is determined by relative return significance rather than the passage of time alone.
Higher percentile settings make the model increasingly selective, while lower settings allow the baseline to update more frequently.
2. SPMA Supertrend
The SPMA is then used as the center of a conventional trailing-band Supertrend architecture.
ATR defines the volatility distance around the event-driven baseline, while the trailing-band logic converts the structure into persistent bullish and bearish regimes.
- Bullish — price has cleared the upper trailing structure and the lower band becomes active.
- Bearish — price has cleared the lower trailing structure and the upper band becomes active.
This produces a hybrid model combining percentile-ranked price displacement, selective baseline updating, volatility normalization, and Supertrend state persistence.
Visuals & Interpretation
Only the active Supertrend boundary is displayed.
A gradient extends between the hidden SPMA baseline and the active Supertrend level, making the relationship between the event-driven baseline and current trend boundary visible without adding unnecessary chart clutter.
Candles are also colored according to the active regime.
Three visual presets are included:
- Standard
- Nordic
- Simple
Practical Application
SPMA Supertrend is designed for identifying directional market structure while reducing the influence of routine price movement on the underlying trend baseline.
The key distinction from a standard Supertrend is simple:
The volatility bands still respond continuously, but the underlying baseline only evolves when price movement is sufficiently significant relative to its recent distribution.
Users can independently control the baseline horizon, percentile-ranking window, percentile gate, ATR horizon, and Supertrend volatility multiplier.
Automated Alerts
Built-in alerts are included for both directional transitions:
- Bullish Flip — triggers when SPMA Supertrend changes from bearish to bullish.
- Bearish Flip — triggers when SPMA Supertrend changes from bullish to bearish.
For closed-bar confirmation, configure TradingView alerts to trigger Once Per Bar Close.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
🔵 Access our best trading & investing tools, get a 30-day free trial today: whop.com/nordic-alpha-lab/
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
🔵 Access our best trading & investing tools, get a 30-day free trial today: whop.com/nordic-alpha-lab/
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。