OPEN-SOURCE SCRIPT
NLMS Volatility Trail [BackQuant]

NLMS Volatility Trail [BackQuant]
Overview
NLMS Volatility Trail is an adaptive trend-following overlay that combines a machine-learning style adaptive filter with a volatility-based trailing structure. It is built around the Normalized Least Mean Squares (NLMS) algorithm, then converts that adaptive estimate into an ATR-based trailing line designed to follow directional regimes while filtering out minor noise.
The indicator has two core layers:
The goal is to produce a trend line that is more adaptive than a traditional moving average and more structured than a raw adaptive filter. The NLMS engine learns the underlying price path, while the ATR trail adds volatility-aware confirmation so trend shifts only occur when the adaptive estimate moves meaningfully.
Core idea
Most trend filters use fixed smoothing rules. An EMA, SMA, WMA, or HMA always applies the same mathematical weighting scheme regardless of whether the market is trending, ranging, expanding, or compressing.
NLMS is different. It continuously updates its internal weights based on prediction error.
This means the filter is not just averaging price. It is constantly asking:
The second layer then takes that adaptive estimate and applies an ATR-based trailing mechanism around it. This creates a volatility-adjusted trend trail that reacts to confirmed shifts while ignoring smaller movements that do not exceed the range structure.
What NLMS is
NLMS stands for Normalized Least Mean Squares. It is an adaptive filtering algorithm from digital signal processing. It is closely related to the original LMS algorithm developed by Bernard Widrow and Ted Hoff, which became one of the foundational online learning methods used in adaptive systems.
Adaptive filters have historically been used in:
The basic purpose is to estimate or predict a signal while continuously adapting to changing conditions.
In trading terms, this indicator uses NLMS to build a learned estimate of price from prior bars.
How the NLMS filter works
The filter uses a set of historical inputs called taps.
If taps = 72, the model uses the previous 72 bars:
Each tap has a learned weight.
The prediction is calculated as:
The filter then compares the prediction to the actual current source:
That error drives the weight update.
If the prediction was poor, the weights adjust more.
If the prediction was accurate, the weights adjust less.
This creates an adaptive estimate that evolves with market behavior.
Why it is normalized
The normal LMS algorithm updates weights based on the raw input and prediction error. The issue is that if the input signal becomes large or volatile, updates can become unstable.
NLMS solves this by dividing the update by the input power:
The update becomes:
This normalization makes the learning process more stable across different volatility environments.
When the input power is high:
When the input power is low:
This is why NLMS is better suited to markets than a basic adaptive filter. Markets constantly shift between quiet and volatile regimes.
Weight initialization
The script initializes all weights equally:
This means the filter starts with an SMA-like prior. Before learning begins, every historical bar contributes equally.
Over time, the filter adapts away from that equal-weight baseline and learns its own weighting structure.
Inputs that control the NLMS engine
Filter Taps (M)
Controls how many historical bars the model learns from.
Higher taps:
Lower taps:
Step Size (μ)
Controls the learning rate.
Lower μ:
Higher μ:
This is one of the most important settings. It controls how quickly the model changes its internal weights.
Regularization (ε)
Prevents instability when input power is very low.
It acts as a stabilizer in the denominator:
Higher values make updates more conservative.
Lower values allow stronger adaptation but can become less stable in quiet conditions.
From adaptive filter to volatility trail
The raw NLMS output is not plotted directly as the main trend line. Instead, it is passed into a volatility trailing structure.
The script builds an ATR band around the NLMS estimate:
Then it creates a trailing value that only updates when the NLMS band structure forces it to move.
This creates a trail that behaves similarly to a volatility stop, but the center is not price or hl2. It is the learned NLMS estimate.
ATR volatility trail logic
The trail starts from the NLMS output, then carries forward its previous value:
Then:
This creates a directional trailing structure:
It filters out small movements because price must move enough relative to ATR and the adaptive estimate to change the trail direction.
Why combine NLMS with ATR
NLMS alone gives an adaptive estimate, but it can still wiggle as the model learns.
ATR alone gives volatility structure, but it is usually tied to raw price and fixed smoothing.
Combining them gives:
The NLMS model learns the underlying price behavior, while ATR decides whether movement is large enough to matter.
Trend direction
Trend flips are detected from the trail itself:
This means signals are generated when the volatility trail changes direction, not when price simply crosses the line.
That is important because:
Visual design
The indicator includes several visual layers.
Main trail line
The central plotted line is the NLMS ATR trail. It changes color based on the current trend state:
Gradient fill
The script fills the space between price and the trail:
The fill is stronger near the trail and fades toward price, making the trail feel like the active structural reference.
Trail glow
A soft glow is drawn around the trail using a small ATR offset:
This highlights the trail visually without cluttering the chart.
Trend candles
Candles are colored by trend state:
This allows the script to function as a complete regime overlay.
How to interpret the indicator
Bullish state
A bullish state occurs when the NLMS volatility trail turns upward.
This suggests:
Bearish state
A bearish state occurs when the NLMS volatility trail turns downward.
This suggests:
Price above the trail
Generally indicates bullish structure.
Price below the trail
Generally indicates bearish structure.
But the most important signal is the direction of the trail itself, not every price touch.
How to use it in practice
1) Trend following
Use the trail direction as the primary bias:
2) Dynamic support/resistance
The trail can act like a dynamic structural level:
3) Trade management
The trail can be used as:
4) Regime filtering
Because the line adapts using NLMS and only flips when the volatility trail turns, it can be used to filter other entries:
Difference from normal Supertrend or ATR trails
A normal ATR trail is usually built directly from price or hl2.
This indicator is different because the trail is built around an adaptive learned estimate.
That means:
So the trail has a different character:
Difference from the NLMS Adaptive Trend Filter
The NLMS Adaptive Trend Filter plots the learned estimate directly and reads trend from its slope.
NLMS Volatility Trail goes one step further:
So this version is more structure-oriented and better suited for trailing trend behavior.
Parameter tuning
Taps
Use higher taps for smoother trend structure.
Use lower taps for faster adaptation.
Step Size
Use lower step size for stability.
Use higher step size for responsiveness.
Regularization
Use higher regularization when the filter feels unstable.
Use lower regularization when the filter is too sluggish.
ATR Period
Controls volatility estimate:
ATR Factor
Controls band width:
Strengths
Limitations
Summary
NLMS Volatility Trail combines an adaptive NLMS predictor with an ATR-based trailing structure. The NLMS layer continuously learns a dynamic estimate of price from historical bars, while the ATR trail converts that estimate into a cleaner directional regime line. This makes the indicator more adaptive than a traditional moving average and more structured than a raw adaptive filter. It is best used as a trend-following overlay, dynamic support/resistance guide, and volatility-aware trailing framework.
Overview
NLMS Volatility Trail is an adaptive trend-following overlay that combines a machine-learning style adaptive filter with a volatility-based trailing structure. It is built around the Normalized Least Mean Squares (NLMS) algorithm, then converts that adaptive estimate into an ATR-based trailing line designed to follow directional regimes while filtering out minor noise.
The indicator has two core layers:
- An NLMS adaptive filter, which learns a dynamic price estimate from prior bars.
- An ATR volatility trail, which converts that learned estimate into a step-like directional trailing structure.
The goal is to produce a trend line that is more adaptive than a traditional moving average and more structured than a raw adaptive filter. The NLMS engine learns the underlying price path, while the ATR trail adds volatility-aware confirmation so trend shifts only occur when the adaptive estimate moves meaningfully.
Core idea
Most trend filters use fixed smoothing rules. An EMA, SMA, WMA, or HMA always applies the same mathematical weighting scheme regardless of whether the market is trending, ranging, expanding, or compressing.
NLMS is different. It continuously updates its internal weights based on prediction error.
This means the filter is not just averaging price. It is constantly asking:
- How well did the previous weighting structure predict the current bar?
- How large was the error?
- How should the weights adjust to reduce future error?
The second layer then takes that adaptive estimate and applies an ATR-based trailing mechanism around it. This creates a volatility-adjusted trend trail that reacts to confirmed shifts while ignoring smaller movements that do not exceed the range structure.
What NLMS is
NLMS stands for Normalized Least Mean Squares. It is an adaptive filtering algorithm from digital signal processing. It is closely related to the original LMS algorithm developed by Bernard Widrow and Ted Hoff, which became one of the foundational online learning methods used in adaptive systems.
Adaptive filters have historically been used in:
- Noise cancellation
- Echo cancellation
- Telecommunications
- Radar and sonar processing
- Signal prediction
- Control systems
The basic purpose is to estimate or predict a signal while continuously adapting to changing conditions.
In trading terms, this indicator uses NLMS to build a learned estimate of price from prior bars.
How the NLMS filter works
The filter uses a set of historical inputs called taps.
If taps = 72, the model uses the previous 72 bars:
- source[1]
- source[2]
- source[3]
- ...
- source[72]
Each tap has a learned weight.
The prediction is calculated as:
- prediction = w1 × source[1] + w2 × source[2] + ... + wM × source[M]
The filter then compares the prediction to the actual current source:
- error = source - prediction
That error drives the weight update.
If the prediction was poor, the weights adjust more.
If the prediction was accurate, the weights adjust less.
This creates an adaptive estimate that evolves with market behavior.
Why it is normalized
The normal LMS algorithm updates weights based on the raw input and prediction error. The issue is that if the input signal becomes large or volatile, updates can become unstable.
NLMS solves this by dividing the update by the input power:
- power = sum(source²)
The update becomes:
- w = w + (μ / (ε + power)) × error × input
This normalization makes the learning process more stable across different volatility environments.
When the input power is high:
- Updates are scaled down.
- The filter avoids overreacting.
When the input power is low:
- Updates are allowed to remain meaningful.
This is why NLMS is better suited to markets than a basic adaptive filter. Markets constantly shift between quiet and volatile regimes.
Weight initialization
The script initializes all weights equally:
- weight = 1 / M
This means the filter starts with an SMA-like prior. Before learning begins, every historical bar contributes equally.
Over time, the filter adapts away from that equal-weight baseline and learns its own weighting structure.
Inputs that control the NLMS engine
Filter Taps (M)
Controls how many historical bars the model learns from.
Higher taps:
- More memory
- Smoother adaptive estimate
- Slower response to regime change
Lower taps:
- Less memory
- Faster reaction
- More noise sensitivity
Step Size (μ)
Controls the learning rate.
Lower μ:
- Slower learning
- Smoother output
- More stable
Higher μ:
- Faster learning
- More responsive
- Can become noisy if too aggressive
This is one of the most important settings. It controls how quickly the model changes its internal weights.
Regularization (ε)
Prevents instability when input power is very low.
It acts as a stabilizer in the denominator:
- ε + power
Higher values make updates more conservative.
Lower values allow stronger adaptation but can become less stable in quiet conditions.
From adaptive filter to volatility trail
The raw NLMS output is not plotted directly as the main trend line. Instead, it is passed into a volatility trailing structure.
The script builds an ATR band around the NLMS estimate:
- Upper band = NLMS output + ATR × factor
- Lower band = NLMS output - ATR × factor
Then it creates a trailing value that only updates when the NLMS band structure forces it to move.
This creates a trail that behaves similarly to a volatility stop, but the center is not price or hl2. It is the learned NLMS estimate.
ATR volatility trail logic
The trail starts from the NLMS output, then carries forward its previous value:
- nlmsAtr := previous nlmsAtr
Then:
- If lower band rises above the trail, the trail moves up.
- If upper band falls below the trail, the trail moves down.
This creates a directional trailing structure:
- In bullish regimes, the trail ratchets upward.
- In bearish regimes, the trail ratchets downward.
It filters out small movements because price must move enough relative to ATR and the adaptive estimate to change the trail direction.
Why combine NLMS with ATR
NLMS alone gives an adaptive estimate, but it can still wiggle as the model learns.
ATR alone gives volatility structure, but it is usually tied to raw price and fixed smoothing.
Combining them gives:
- Adaptive intelligence from NLMS.
- Volatility confirmation from ATR.
- Cleaner trend state transitions.
- Less dependence on fixed moving-average assumptions.
The NLMS model learns the underlying price behavior, while ATR decides whether movement is large enough to matter.
Trend direction
Trend flips are detected from the trail itself:
- Bullish when nlmsAtr crosses above its previous value.
- Bearish when nlmsAtr crosses below its previous value.
This means signals are generated when the volatility trail changes direction, not when price simply crosses the line.
That is important because:
- The trail must structurally move.
- The signal is tied to confirmed trail direction.
- Noise around the line does not automatically create a flip.
Visual design
The indicator includes several visual layers.
Main trail line
The central plotted line is the NLMS ATR trail. It changes color based on the current trend state:
- Green for bullish trail direction.
- Red for bearish trail direction.
- Gray before a trend state is established.
Gradient fill
The script fills the space between price and the trail:
- If price is above the trail, bullish fill is shown.
- If price is below the trail, bearish fill is shown.
The fill is stronger near the trail and fades toward price, making the trail feel like the active structural reference.
Trail glow
A soft glow is drawn around the trail using a small ATR offset:
- glow = ATR(14) × 0.06
This highlights the trail visually without cluttering the chart.
Trend candles
Candles are colored by trend state:
- Bullish trend = bullish candles.
- Bearish trend = bearish candles.
This allows the script to function as a complete regime overlay.
How to interpret the indicator
Bullish state
A bullish state occurs when the NLMS volatility trail turns upward.
This suggests:
- The adaptive filter is shifting higher.
- The ATR trail has confirmed upward structure.
- Trend pressure has turned bullish.
Bearish state
A bearish state occurs when the NLMS volatility trail turns downward.
This suggests:
- The adaptive estimate is shifting lower.
- The volatility trail has confirmed downside structure.
- Trend pressure has turned bearish.
Price above the trail
Generally indicates bullish structure.
Price below the trail
Generally indicates bearish structure.
But the most important signal is the direction of the trail itself, not every price touch.
How to use it in practice
1) Trend following
Use the trail direction as the primary bias:
- Favor longs when the trail is bullish.
- Favor shorts when the trail is bearish.
2) Dynamic support/resistance
The trail can act like a dynamic structural level:
- In uptrends, pullbacks toward the trail can act as support.
- In downtrends, rallies toward the trail can act as resistance.
3) Trade management
The trail can be used as:
- A trailing stop guide.
- A regime invalidation level.
- A trend continuation reference.
4) Regime filtering
Because the line adapts using NLMS and only flips when the volatility trail turns, it can be used to filter other entries:
- Take only long setups during bullish trail regimes.
- Take only short setups during bearish trail regimes.
- Avoid countertrend trades when the trail is strongly directional.
Difference from normal Supertrend or ATR trails
A normal ATR trail is usually built directly from price or hl2.
This indicator is different because the trail is built around an adaptive learned estimate.
That means:
- The centerline is not raw price.
- It is not a fixed moving average.
- It is a continuously learned NLMS estimate.
So the trail has a different character:
- More adaptive than a standard moving average trail.
- More stable than a raw price-based ATR stop.
- More responsive to changing market structure than fixed filters.
Difference from the NLMS Adaptive Trend Filter
The NLMS Adaptive Trend Filter plots the learned estimate directly and reads trend from its slope.
NLMS Volatility Trail goes one step further:
- It uses the learned estimate as the base.
- Then wraps it with ATR structure.
- Then turns that into a trailing regime line.
So this version is more structure-oriented and better suited for trailing trend behavior.
Parameter tuning
Taps
Use higher taps for smoother trend structure.
Use lower taps for faster adaptation.
Step Size
Use lower step size for stability.
Use higher step size for responsiveness.
Regularization
Use higher regularization when the filter feels unstable.
Use lower regularization when the filter is too sluggish.
ATR Period
Controls volatility estimate:
- Shorter = more reactive trail.
- Longer = smoother trail.
ATR Factor
Controls band width:
- Higher factor = wider trail, fewer flips.
- Lower factor = tighter trail, more flips.
Strengths
- Combines adaptive filtering with volatility trailing logic.
- Learns from market structure instead of using fixed weights.
- Uses ATR to reduce noise and confirm meaningful movement.
- Good for trend following and trailing stop frameworks.
- Visually clean with gradient fill and candle coloring.
Limitations
- Still reactive, not predictive.
- Can lag during violent reversals.
- High learning rates may create noise.
- Low ATR factors may cause whipsaws.
- Requires tuning for timeframe and asset volatility.
Summary
NLMS Volatility Trail combines an adaptive NLMS predictor with an ATR-based trailing structure. The NLMS layer continuously learns a dynamic estimate of price from historical bars, while the ATR trail converts that estimate into a cleaner directional regime line. This makes the indicator more adaptive than a traditional moving average and more structured than a raw adaptive filter. It is best used as a trend-following overlay, dynamic support/resistance guide, and volatility-aware trailing framework.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
Check out whop.com/signals-suite for Access to Invite Only Scripts!
Or go to backquant.com/
Or go to backquant.com/
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
Check out whop.com/signals-suite for Access to Invite Only Scripts!
Or go to backquant.com/
Or go to backquant.com/
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.