SuperTrend AI (Clustering)

Aug 14, 2023

Static chart image
Dynamic Overlays
Signals
Machine Learning
Trailing-Stop
Works on the following platforms:
tradingviewSymbolTradingView
For free use on the TradingView platform
ninjatraderNinjaTrader
For free use on the NinjaTrader platform
metatrader4MetaTrader 4
For free use on the MetaTrader 4 platform
metatrader5MetaTrader 5
For free use on the MetaTrader 5 platform
thinkorswimThinkorswim
For free use on the Thinkorswim platform

The SuperTrend AI indicator ingeniously integrates the sophisticated K-means clustering machine learning technique with the practical utility of trading indicators. By applying K-Means clustering to the revered SuperTrend indicator, traders receive advanced insights into market trends, significantly enhancing their trading strategies.

How to Trade with the SuperTrend AI Indicator?

indicator image

Traders can leverage the SuperTrend AI indicator similarly to the traditional SuperTrend by understanding its trailing stop signals. Higher minimum and maximum factors generate signals favorable for long-term trading strategies. The indicator provides performance metrics on each signal, offering a deeper analysis by highlighting potential market trends. Higher metric values often suggest a strong trend, unlike lower values which could imply possible retracements.

indicator image

The image above illustrates the performance metrics accompanying each signal, indicating possible trends. However, traders should remain aware that these performance metrics are not foolproof and may not predict every signal accurately.

indicator image

In this image, the trailing stop, along with its adaptive moving average, serves as a support and resistance level. Adjusting the performance memory setting to a higher value enables traders to view a long-term adaptive moving average for the trailing stop, improving their trading strategy.

Understanding K-Means Clustering

What is K-Means Clustering?

indicator image

K-Means clustering involves observing data points and forming groups or "clusters" of data that are close to each other. While visually identifying clusters may appear easy, mathematical computation can be complex. Cluster analysis seeks to group similar data points, and among numerous methods, K-Means Clustering stands out as a simple and iterative unsupervised technique ideal for dividing data into a predetermined number of clusters.

The K-Means algorithm can be simplified into these steps to identify K clusters:

  • (1) Decide the number (K) of clusters to identify.
  • (2) Randomly initialize K centroids (cluster centers).
  • (3) Assign each data point to the nearest centroid and associate it with that cluster.
  • (4) Update centroids by computing the average of the associated data points.
  • Repeat steps 3 and 4 until the centroids stabilize.

For illustrative purposes, consider a one-dimensional dataset featuring two evident clusters:

indicator image

While this example is basic, real-world applications typically involve a larger set of data points and clusters. Note that the initial values for centroids significantly impact the outcome, hence multiple runs are often needed to identify the optimal centroids.

Adaptive SuperTrend Factor with K-Means

Our indicator design follows a modern hypothesis:

Across multiple indicator instances with variable settings, the optimal configuration at any time t comes from the strongest performing instance with configuration s(t).

By calculating the indicator with the leading configuration at time t, we can adapt its features based on performance. Still, significant disparity between the top-performing instance and its runner-ups, despite minor performance differences, is possible but rare. Often, similar performance among settings can be seen through a parameter optimization heatmap. Hence, refining settings to include group averages over singular bests enhances flexibility:

Across diverse indicator instances with alternative settings, a suitable configuration at time t derives from the weighted average of top-performing instance settings s(t).

Identifying these peak-performing instances can employ K-Means clustering, assuming a trio of interest groups (K=3) as below-average, average, and exceptional performers.

Initially, performance P(t, factor) is calculated as:

P(t, factor) = P(t-1, factor) + α * (∆C(t) × S(t-1, factor) - P(t-1, factor))

Where α ranges between 0 and 1, determining past inputs' influence on current results. Here, C(t) represents the closing price, while S(t, factor) is the SuperTrend signal generating function with factor factor.

The function runs for various factor settings executing K-Means clustering on numerous performance measures to pinpoint the top-performing cluster, with centroid initiation via performance quartiles speeding convergence.

indicator image

The optimal factor setting, derived from the mean of the top-performing cluster's factors, computes the final SuperTrend output. Flexibility is allowed to extract the final factor from any cluster, pure experimentation if desired.

Configuration Settings

  • ATR Length: Period for ATR calculation in SuperTrend.
  • Factor Range: Sets the minimum and maximum values for SuperTrend factor calculation.
  • Step: Increments within the factor range.
  • Performance Memory: Governs how historical inputs impact the present output, with higher values indicating long-term performance measures.
  • From Cluster: Designates which cluster determines the final factor.

Performance Optimization

  • Maximum Iteration Steps: Caps the iterations for centroid discovery, balancing computational time against optimal clustering.
  • Historical Bars Calculation: The script's timeframe window (in bars).

FAQs

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

What role does performance memory play in SuperTrend AI? Performance memory tuning affects the extent historical data influences ongoing analysis, crucial for long-term market predictions.

Can SuperTrend AI indicator forecast a price trend in real-time? While it's equipped with real-time capabilities, the SuperTrend AI indicator should be used alongside other tools for effective trend analysis.

Trading is risky and many will lose money in connection with trading 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 markets 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 for charting platforms, 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 or tool we provide.

Charts used on this site are by TradingView in which the majority of our tools 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.

This does not represent our full Disclaimer. Please read our full disclaimer.

© 2025 LuxAlgo Global, LLC.