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.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.