# SuperTrend AI (Clustering)

SuperTrend AI (Clustering) is an indicator on [Vela](https://vela.luxalgo.com/chart), our next-generation charting platform, written in Pine Script®.

A SuperTrend that picks its own factor: the indicator runs the calculation across a whole factor range, measures how each instance performs, and k-means-clusters the results so the live trailing stop uses the strongest group's settings. Signals print a performance metric, and an adaptive average doubles as support and resistance.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Aug 14, 2023.
- Access: free.
- Concepts: [Supertrend](https://www.luxalgo.com/library/concept/supertrend/) (primary), [K-means Regime Clustering](https://www.luxalgo.com/library/concept/k-means-regime-clustering/)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=cmpwn61f2008ivhsgv89yyf6o
- Page: https://www.luxalgo.com/library/indicator/supertrend-ai-clustering/

**SuperTrend AI (Clustering)** lets performance data choose the settings. The indicator evaluates the [SuperTrend trailing stop](https://www.luxalgo.com/library/concept/supertrend/) across a user-defined factor range, scores how each instance has performed, and applies [k-means clustering](https://www.luxalgo.com/library/concept/k-means-regime-clustering/) with three groups (below-average, average, and exceptional) to that performance set. The factor driving the on-chart stop is drawn from the chosen cluster's average, with centroids initialized from performance quartiles to speed convergence.

## How to Trade the SuperTrend AI (Clustering)?

- **Trailing stop flips**: read them like the classic. The stop below price marks an uptrend, above price a downtrend.
- **Signal performance metric**: each signal prints a value; higher readings tend to accompany stronger trends, lower ones warn of possible retracements. Informative, not foolproof.
- **Stop plus adaptive average as S/R**: both can serve as support and resistance; raising Performance Memory produces a longer-term adaptive moving average.
- **Factor range choice**: higher minimum and maximum factors favor signals suited to longer-term positioning.

## SuperTrend AI (Clustering) Settings

- **ATR Length**: period of the ATR in the SuperTrend calculation.
- **Factor Range**: minimum and maximum factors evaluated.
- **Step**: increment between tested factors.
- **Performance Memory**: how much history weighs on performance scores; higher values emphasize the long run.
- **From Cluster**: which cluster (best, average, or worst) supplies the final factor.
- **Maximum Iteration Steps / Historical Bars Calculation**: caps on centroid iterations and the calculation window.

## Frequently Asked Questions

### How is the final factor actually selected?

Each factor's performance is tracked bar by bar, the results are clustered with k-means (K=3), and the factors in your selected cluster are averaged into the one that computes the plotted SuperTrend. By default that is the top-performing cluster, though From Cluster invites experimentation.

### Is there an oscillator version of this idea?

Yes. The [AI SuperTrend Clustering Oscillator](https://www.luxalgo.com/library/indicator/ai-supertrend-clustering-oscillator/) carries the same clustering approach into a separate-pane format, if you prefer momentum-style reads over an on-chart stop.

### What does SuperTrend AI (Clustering) cost?

Nothing. It is free on the LuxAlgo Library, and Quant, our coding agent, can backtest its signals directly from this page. You can also copy the source code from this page and run it anywhere Pine Script® runs.

## Related indicators

- [Supertrend Channels](https://www.luxalgo.com/library/indicator/supertrend-channels/) (Supertrend): markdown at https://www.luxalgo.com/library/indicator/supertrend-channels.md
- [SuperTrend Oscillator](https://www.luxalgo.com/library/indicator/supertrend-oscillator/) (Supertrend): markdown at https://www.luxalgo.com/library/indicator/supertrend-oscillator.md
- [SuperTrend Recovery](https://www.luxalgo.com/library/indicator/supertrend-recovery/) (Supertrend): markdown at https://www.luxalgo.com/library/indicator/supertrend-recovery.md
- [SuperTrend Polyfactor Oscillator](https://www.luxalgo.com/library/indicator/supertrend-polyfactor-oscillator/) (Supertrend): markdown at https://www.luxalgo.com/library/indicator/supertrend-polyfactor-oscillator.md
- [Supertrend Parameter Sensitivity 3D](https://www.luxalgo.com/library/indicator/supertrend-parameter-sensitivity-3d/) (Supertrend): markdown at https://www.luxalgo.com/library/indicator/supertrend-parameter-sensitivity-3d.md
- [Evasive SuperTrend](https://www.luxalgo.com/library/indicator/evasive-supertrend/) (Supertrend): markdown at https://www.luxalgo.com/library/indicator/evasive-supertrend.md
- [Correlation Clusters](https://www.luxalgo.com/library/indicator/correlation-clusters/) (K-means Regime Clustering): markdown at https://www.luxalgo.com/library/indicator/correlation-clusters.md
- [AI Channels (Clustering)](https://www.luxalgo.com/library/indicator/ai-channels-clustering/) (K-means Regime Clustering): markdown at https://www.luxalgo.com/library/indicator/ai-channels-clustering.md

---

Source: https://www.luxalgo.com/library/indicator/supertrend-ai-clustering/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
