All indicators

Machine Learning Trendlines Cluster

By LuxAlgoMar 19, 2025

Machine Learning Trendlines Cluster is an indicator on Vela, our next-generation charting platform, written in Pine Script®.

Static chart image

Machine Learning Trendlines Cluster hands the drawing of trendlines 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 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

Free to use

Run it on Vela. Go further with a paid plan.

  • Up to 500 strategy alerts, with webhook automation
  • Up to 10× the chart history of Free
  • Orderflow lookback up to full history
  • More Quant usage to customize it, plus extra usage when you need it
  • Futures data alongside crypto, stocks, forex and commodities
See plans

Also works on

TradingView
Original indicatorBuilt in-house by LuxAlgo
All 10 Trendline indicators

Run it on Vela. Make it yours with Quant.

Open this indicator free on Vela, our next-generation charting platform. Then ask Quant, our coding agent built into Vela, to retune it or turn it into a backtested strategy of your own.