OPEN-SOURCE SCRIPT
Ultimate Supertrend

1. The Core: NLMS Adaptive Filter
At its heart is the Normalized Least Mean Squares (NLMS) filter. Unlike a standard moving average (SMA/EMA) that statically averages the last X bars, the NLMS is an "online" machine-learning predictor.
It looks at the past M bars (taps) and uses gradient descent to calculate "weights" that best predict the current price.
The Step Size (μ) dictates how aggressively it learns. A higher step size makes it hug the price very closely (reactive), while a lower step size keeps the baseline smooth.
This creates an incredibly adaptive baseline that tracks market movement more intelligently than traditional moving averages.
2. Volatility Bands (ATR)
Instead of just using the raw NLMS line, the script applies an Average True Range (ATR) multiplier on top of it.
It calculates an upper and lower boundary based on the ATR around the NLMS baseline.
If the baseline tries to move past these upper/lower extremes, the indicator "ratchets" or snaps the trailing line to the boundary.
This creates the characteristic "stair-step" trailing stop behavior you see in Supertrends.
3. Trend Direction & Signals
The indicator determines the trend by looking at the trajectory of the final NLMS-ATR trailing line:
Bullish Trend (Green): Triggered when the trailing line ticks upward (crosses over its previous value).
Bearish Trend (Red): Triggered when the trailing line ticks downward (crosses under its previous value).
It fires automated alert conditions (alertcondition) whenever these trend flips occur.
4. Visual Enhancements
To make it visually intuitive for trading, the script includes premium aesthetics:
Trend Candles: Automatically paints the actual price candles green or red depending on the current trend.
Gradient Fills: Fills the area between the price and the trailing line, fading softly towards the price to show momentum density.
Trail Glow: Adds a sleek visual glow (semi-transparent bands) around the trailing line itself.
In short, it’s a highly-responsive, volatility-adjusted trailing stop that uses an adaptive algorithm to filter out market noise while keeping you on the right side of the trend.
At its heart is the Normalized Least Mean Squares (NLMS) filter. Unlike a standard moving average (SMA/EMA) that statically averages the last X bars, the NLMS is an "online" machine-learning predictor.
It looks at the past M bars (taps) and uses gradient descent to calculate "weights" that best predict the current price.
The Step Size (μ) dictates how aggressively it learns. A higher step size makes it hug the price very closely (reactive), while a lower step size keeps the baseline smooth.
This creates an incredibly adaptive baseline that tracks market movement more intelligently than traditional moving averages.
2. Volatility Bands (ATR)
Instead of just using the raw NLMS line, the script applies an Average True Range (ATR) multiplier on top of it.
It calculates an upper and lower boundary based on the ATR around the NLMS baseline.
If the baseline tries to move past these upper/lower extremes, the indicator "ratchets" or snaps the trailing line to the boundary.
This creates the characteristic "stair-step" trailing stop behavior you see in Supertrends.
3. Trend Direction & Signals
The indicator determines the trend by looking at the trajectory of the final NLMS-ATR trailing line:
Bullish Trend (Green): Triggered when the trailing line ticks upward (crosses over its previous value).
Bearish Trend (Red): Triggered when the trailing line ticks downward (crosses under its previous value).
It fires automated alert conditions (alertcondition) whenever these trend flips occur.
4. Visual Enhancements
To make it visually intuitive for trading, the script includes premium aesthetics:
Trend Candles: Automatically paints the actual price candles green or red depending on the current trend.
Gradient Fills: Fills the area between the price and the trailing line, fading softly towards the price to show momentum density.
Trail Glow: Adds a sleek visual glow (semi-transparent bands) around the trailing line itself.
In short, it’s a highly-responsive, volatility-adjusted trailing stop that uses an adaptive algorithm to filter out market noise while keeping you on the right side of the trend.
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.