All indicators

NLMS Adaptive Trend Filter

Jun 8, 2026

Static chart image
Price Action BasedSupport and ResistanceSignalsMachine LearningMoving Averages

The NLMS Adaptive Trend Filter indicator provides a machine learning-inspired trend-following model based on the Normalized Least Mean Squares algorithm to dynamically adapt to evolving market conditions. Unlike traditional moving averages that use fixed weighting, this tool continuously learns from prediction errors to update its internal coefficients in real time, offering a more responsive and stable trend estimate.

Usage

The Usage section describes how the script can be used to identify market regimes and potential trend reversals. Users can monitor the slope of the adaptive filter line to determine the current trend direction.

  • Trend Identification: A bullish trend is indicated when the NLMS output is rising (colored green/bullish), while a bearish trend is indicated when the output is falling (colored red/bearish).
  • Trend Flips: "Bullish Flips" occur when the filter transitions from a declining to a rising slope, signaling a potential long entry. Conversely, "Bearish Flips" occur when the filter transitions from a rising to a falling slope.
  • Dynamic Support and Resistance: The filter line acts as a dynamic threshold. Traders often look for price interactions with the line, such as crossovers or bounces, to confirm trend strength or exhaustion.
  • Visual Context: The gradient fill between the price and the filter line helps visualize the distance from the learned mean, while the optional candle coloring aligns price action with the model's internal state.

Details

The NLMS Adaptive Trend Filter is built upon digital signal processing principles originally developed by Bernard Widrow and Ted Hoff. The core mechanism is a one-step linear predictor that uses a specific number of historical observations, known as "Taps."

At each new bar, the algorithm:

  1. Generates a prediction for the current price based on previous data and current weights.
  2. Calculates the prediction error (Actual Price - Predicted Price).
  3. Updates the weights using a normalized gradient descent rule.

Normalization is a critical component of this script; it scales the weight updates according to the energy (volatility) of the input signal. This ensures that the learning process remains stable during high-volatility spikes and sufficiently reactive during low-volatility consolidation. Initially, the filter starts with equal weights, behaving like a Simple Moving Average (SMA), before evolving into a custom weighting structure optimized for the specific asset's behavior.

Settings

  • Source: Determines the price data used for the filter calculations (default is Close).
  • Filter Taps (M): The number of past observations used to generate predictions. Higher values provide a smoother, longer-term perspective, while lower values increase responsiveness.
  • Step Size (μ): The learning rate of the algorithm. Larger values allow the filter to adapt quickly to new price movements but may introduce noise. Smaller values result in a more stable, conservative trend line.
  • Regularization (ε): A safety factor used to prevent numerical instability or division-by-zero errors during periods of extremely low volatility.
  • Output Smoothing: Applies an optional EMA to the final NLMS output for cosmetic clarity. Setting this to 1 disables the smoothing.
  • Show Filter Line: Toggles the visibility of the main adaptive trend line.
  • Gradient Fill: Enables or disables the color shading between the price and the filter line.
  • Color Candles: When enabled, candles are colored based on the current directional state of the NLMS filter.

FAQ

How does NLMS differ from an EMA? While an EMA uses a fixed multiplier to weight recent data, the NLMS filter dynamically adjusts its weighting for every tap based on how well those specific weights predicted previous price action.

What is the best "Step Size" to use? The optimal step size depends on your strategy. Use a smaller μ (e.g., 0.01) for long-term trend following and a larger μ (e.g., 0.1) for reactive, short-term filtering.

How do I access this indicator? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.