Machine Learning Adaptive SuperTrend
Aug 7, 2024

The Machine Learning Adaptive SuperTrend indicator utilizes k-means clustering to dynamically categorize market volatility, allowing the traditional SuperTrend strategy to adapt more effectively to changing market conditions.
Usage
The Usage section focuses on identifying trend reversals and volatility shifts using the indicator's visual cues.
- Trend Identification: The indicator plots a colored line on the chart; a change from red to green suggests a bullish trend shift, while a change from green to red suggests a bearish shift. Labels marked with triangles (▲/▼) indicate the exact point of the reversal.
- Volatility Analysis: Small numeric labels (1-3) appear near the SuperTrend line, representing the current volatility regime determined by the machine learning algorithm.
- 3: High Volatility
- 2: Medium Volatility
- 1: Low Volatility
- Data Table: A dashboard in the top-right corner provides real-time details on cluster centroids (the average ATR for that regime), cluster sizes, and the current active volatility state.
Details
This tool improves upon the standard SuperTrend by replacing the static ATR input with an assigned centroid from a k-means clustering algorithm.
The algorithm operates by:
- Data Collection: Gathering ATR values over a user-defined training period.
- Clustering: Partitioning these ATR values into three distinct groups (High, Medium, and Low) based on their similarity.
- Iterative Optimization: The script iterates to find the most accurate "center" (centroid) for each cluster.
- Adaptive Calculation: The SuperTrend line is then calculated using the centroid value of the cluster that the current price action most closely matches. This ensures the indicator is wider during high volatility to avoid "whipsaws" and tighter during low volatility to capture moves early.
Settings
SuperTrend Settings
- ATR Length: Sets the lookback period for the Average True Range calculation.
- SuperTrend Factor: The multiplier applied to the ATR/Centroid to determine the distance of the bands from price.
K-Means Settings
- Training Data Length: The number of historical bars used to train the clustering algorithm.
- Initial High/Medium/Low Volatility Percentile Guess: Defines the starting points for the algorithm based on the percentile range of the training data.
Appearance
- Transparency 1 & 2: Controls the visibility of the primary line and the background fills.
- Bullish/Bearish Color: Customizes the colors used for trend direction.
FAQ
How do I interpret the cluster numbers?
The numbers 1, 2, and 3 represent Low, Medium, and High volatility respectively. Higher numbers indicate the algorithm has detected a more volatile market environment, causing the SuperTrend to become more adaptive to larger price swings.
Can I use this for automated alerts?
Yes, the script includes built-in alert conditions for both trend shifts (Bullish/Bearish) and changes in volatility regimes, allowing you to stay informed without monitoring the chart constantly.
How do I access Machine Learning Adaptive SuperTrend?
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.

