Adaptive ML Trailing Stop
Dec 23, 2025

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.
Trading & investing are risky and many will lose money in connection with trading and investing activities. All content on this site is not intended to, and should not be, construed as financial advice. Decisions to buy, sell, hold or trade in securities, commodities and other investments involve risk and are best made based on the advice of qualified financial professionals. Past performance does not guarantee future results.
Hypothetical or Simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, including, but not limited to, lack of liquidity. Simulated trading programs in general are designed with the benefit of hindsight, and are based on historical information. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.
Testimonials appearing on this website may not be representative of other clients or customers and is not a guarantee of future performance or success.
As a provider of technical analysis tools and strategies, we do not have access to the personal trading accounts or brokerage statements of our customers. As a result, we have no reason to believe our customers perform better or worse than traders as a whole based on any content, tool, or platform feature we provide.
Charts used on this site are by TradingView in which the majority of our technical indicators are built on. TradingView® is a registered trademark of TradingView, Inc. www.TradingView.com TradingView® has no affiliation with the owner, developer, or provider of the Services described herein.
Market data is provided by CBOE, CME Group, BarChart, Massive, CoinAPI. Select U.S. equities data is provided through Massive. CBOE BZX real-time U.S. equities data is licensed from CBOE and provided through BarChart. Real-time futures data is licensed from CME Group and provided through BarChart. Select cryptocurrency data, including major coins, is provided through CoinAPI. All data is provided “as is” and should be verified independently for trading purposes.
This does not represent our full Disclaimer. Please read our full disclaimer.
© 2026 LuxAlgo Global, LLC.

