All indicators

Adaptive ML Trailing Stop

Dec 23, 2025

Static chart image
Dynamic OverlaysSignalsMachine LearningTrailing-StopVolatility

The Adaptive ML Trailing Stop indicator provides a regime-sensitive risk control system that dynamically adjusts stop placement based on market efficiency, volatility, and historical pattern resemblance. It uses machine learning and adaptive smoothing to transition between tight trailing during strong trends and relaxed boundaries during rotational market phases.

Usage

The Usage section describes how the script can be used to manage risk and identify trend transitions. The indicator outputs a continuous trailing stop line that changes color based on the detected market regime.

  • Trend Identification: A green trailing stop indicates a bullish regime, while a red stop indicates a bearish regime. Trend transitions are marked by circles when price crosses the opposing stop level.
  • Dynamic Risk Management: Use the trailing stop as a moving invalidation level. During high-efficiency trends (calculated via KAMA), the stop will automatically tighten to protect gains. In choppy or low-efficiency environments, the stop widens to avoid premature exits.
  • Interaction Monitoring: Diamond markers appear when price makes controlled contact with the active stop. These serve as alerts for potential volatility spikes or trend testing.
  • Gradient Interpretation: The gradient fill between the price and the stop visualizes the extension level. Deeper penetration into the gradient suggests price is moving further away from its structural invalidation point.

Details

The indicator integrates three core technical frameworks to determine stop positioning:

  • KAMA Efficiency Engine: Utilizes Kaufman’s Adaptive Moving Average (KAMA) to calculate an Efficiency Ratio (ER). This ratio modulates the smoothing constant, allowing the stop to respond rapidly during directional moves and slow down during noise.
  • Adaptive ATR Engine: Traditional ATR stop logic is modified by market efficiency. The stop distance expands or contracts based on the "Adaptive Strength" setting, ensuring the volatility buffer is context-aware.
  • KNN Pattern Layer: A K-Nearest Neighbors (KNN) algorithm compares recent price action against a historical lookback window. If historical analogs suggest a high probability of a specific direction, the KNN influence shifts the stop distance to favor that outcome, providing a probabilistic bias to the risk envelope.

Settings

KAMA Settings

  • KAMA Length: The lookback period for calculating efficiency.
  • Fast Period: The smoothing constant used when the market is highly efficient (trending).
  • Slow Period: The smoothing constant used when the market is inefficient (ranging).

Trailing Stop Settings

  • ATR Period: The period used for Average True Range volatility calculations.
  • Base ATR Multiplier: The primary multiplier for setting stop distance from price.
  • Adaptive Strength: Determines how much the stop distance reacts to efficiency changes.

KNN Machine Learning

  • Enable KNN: Toggles the pattern-matching influence on/off.
  • K Neighbors: The number of historical matches to consider for prediction.
  • KNN Lookback Period: The size of the historical window searched for patterns.
  • Pattern Length: The number of bars defining the current price structure for comparison.
  • KNN Influence: The weight the ML prediction has on the final stop distance.

Signal & Visual Settings

  • Diamond Cooldown Bars: Minimum spacing between stop interaction markers to prevent visual clutter.
  • Show Gradient Fill: Toggles the visual depth effect between price and the stop line.

FAQ

How do I adjust the indicator for high-volatility assets? Increase the ATR Period and Base ATR Multiplier to provide a wider buffer, and increase the KAMA Length to filter out erratic price spikes.

What do the diamond markers represent? Diamonds indicate that price has touched or come within a specific proximity of the trailing stop, suggesting a potential test of the current trend regime.

How can I access this tool? 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.