# Machine Learning Trendlines Cluster

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

The Machine Learning Trendlines Cluster draws trendlines algorithmically: k-means clustering groups price into trading ranges, and a linear regression through each cluster becomes a line on the chart. Choose how many lines to detect and filter them by slope: objective trendlines without manual drawing, for traders who distrust hand-picked pivots.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Mar 19, 2025.
- Access: free.
- Concepts: [Trendline](https://www.luxalgo.com/library/concept/trendline/) (primary), [K-means Regime Clustering](https://www.luxalgo.com/library/concept/k-means-regime-clustering/)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=cmpwn3dg8004ovhsgdh4mr6sr
- Page: https://www.luxalgo.com/library/indicator/machine-learning-trendlines-cluster/

**Machine Learning Trendlines Cluster** hands the drawing of [trendlines](https://www.luxalgo.com/library/concept/trendline/) to an algorithm. K-means clustering groups recent bars into price ranges that traded together, and a linear regression fitted through each cluster is plotted as a trendline (4 clusters over the past 500 bars by default). The lines describe where price actually spent its time rather than connecting two hand-picked pivots.

## How to Trade the Machine Learning Trendlines Cluster?

- **Set the line count**: define how many clusters (trendlines) to detect and let the algorithm handle the calculation; raising the count uncovers finer lines inside the same window.
- **Read the slope**: steeper lines come from clusters whose prices rose or fell faster over time, potentially tracing the segments where price moved hardest.
- **Filter by slope**: keep only lines above or below a volatility-scaled threshold to emphasize prominent gradients, or favor the flatter, range-like ones.

Under the hood, [k-means clustering](https://www.luxalgo.com/library/concept/k-means-regime-clustering/) repeatedly assigns bars to their nearest group and recenters each group until variance stops improving, so the plotted regressions settle onto stable price groupings.

## Machine Learning Trendlines Cluster Settings

- **Window Size**: maximum number of bars data is gathered from.
- **Clusters**: maximum number of clusters, and therefore trendlines, to identify.
- **Maximum Iteration Steps**: caps the clustering loop so computation stays efficient.
- **Threshold Multiplier**: volatility-based multiplier for the slope filter; higher values increase its sensitivity.
- **Filter Slopes**: toggles slope filtering and whether lines above or below the threshold are filtered out.
- Style inputs (Upper Zone, Lower Zone, Lines, Size) control zone colors, line style, and thickness.

## Frequently Asked Questions

### How is this different from classic trendline tools?

Conventional tools connect swing highs or lows, so every line depends on which pivots get picked. Here each line is a regression through a cluster of prices sharing a range, a genuinely different angle on the same chart. If you prefer pivot-anchored lines with breakout signals, [Trendlines with Breaks](https://www.luxalgo.com/library/indicator/trendlines-with-breaks/) is the natural sibling.

### What does a steep trendline tell me?

A steeper slope means prices inside that cluster rose or fell faster over time: the bars it summarizes covered more ground. Such lines can flag significant price movements, while flatter ones outline quieter consolidation.

### How do I access the Machine Learning Trendlines Cluster?

It is free in the LuxAlgo Library. Add it to your chart straight from this page. You can also run and backtest it in Quant, our coding agent, without leaving the page. You can also copy the source code from this page and run it anywhere Pine Script® runs.

## Related indicators

- [Trendlines Oscillator](https://www.luxalgo.com/library/indicator/trendlines-oscillator/) (Trendline): markdown at https://www.luxalgo.com/library/indicator/trendlines-oscillator.md
- [Trendlines with Breaks](https://www.luxalgo.com/library/indicator/trendlines-with-breaks/) (Trendline): markdown at https://www.luxalgo.com/library/indicator/trendlines-with-breaks.md
- [Trendline Breakout Navigator](https://www.luxalgo.com/library/indicator/trendline-breakout-navigator/) (Trendline): markdown at https://www.luxalgo.com/library/indicator/trendline-breakout-navigator.md
- [Trendlines with Breaks Oscillator](https://www.luxalgo.com/library/indicator/trendlines-with-breaks-oscillator/) (Trendline): markdown at https://www.luxalgo.com/library/indicator/trendlines-with-breaks-oscillator.md
- [Rolling Trendline](https://www.luxalgo.com/library/indicator/rolling-trendline/) (Trendline): markdown at https://www.luxalgo.com/library/indicator/rolling-trendline.md
- [Power Hour Trendlines](https://www.luxalgo.com/library/indicator/power-hour-trendlines/) (Trendline): markdown at https://www.luxalgo.com/library/indicator/power-hour-trendlines.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/machine-learning-trendlines-cluster/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
