# Correlation Clusters

A machine learning tool that measures the correlation of up to ten selected tickers against a reference symbol and groups them into clusters with k-means. Instead of scanning a matrix cell by cell, traders see at a glance which assets move together, which move inversely, and which offer genuine diversification.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Aug 15, 2024.
- Access: free.
- Concepts: [Correlation](https://www.luxalgo.com/library/concept/correlation/) (primary), [K-means Regime Clustering](https://www.luxalgo.com/library/concept/k-means-regime-clustering/)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=cmpwn0zjl001bvhsgh08ktsqk
- Page: https://www.luxalgo.com/library/indicator/correlation-clusters/

**Correlation Clusters** measures how closely up to ten user-selected tickers track a reference symbol, then sorts them into like-behaving groups automatically. Each pairwise [correlation](https://www.luxalgo.com/library/concept/correlation/) coefficient falls between +1 (moving in tandem) and -1 (moving inversely), and a [k-means clustering](https://www.luxalgo.com/library/concept/k-means-regime-clustering/) pass groups tickers with similar coefficients (up to ten clusters, each color-coded with a dotted centroid line), replacing the manual grind of reading a correlation matrix.

## How to Trade the Correlation Clusters?

- **Same cluster, same risk**: grouped tickers tend to move together. Stacked longs across one cluster concentrate exposure rather than diversify it.
- **Clusters near zero**: behave independently of the reference, the natural place to hunt genuine diversification.
- **Strongly negative clusters**: inverse movers, useful for hedging reference-aligned positions.
- **Divergence inside a tight cluster**: when two highly correlated tickers temporarily split, pair traders buy one and sell the other anticipating reconvergence.

The Execution Window controls the sample: correlations can be gathered over a bar count, a time span such as a day or a week, or all available data, with the default drawing on the last 50 bars. Different windows tell different stories about the same assets, so match the sample to how long you hold.

## Correlation Clusters Settings

- **Execution Window Mode**: collect data by bars, by time, or without filtering.
- **Execute on Last X Bars / Execute on Last**: the sample size for the bars and time modes.
- **Number of Clusters**: up to 10. The algorithm may return fewer when the data lacks distinct groups.
- **Cluster Threshold / Max Iterations**: centroid precision and the iteration budget; defaults suit most uses.
- **Use Chart Ticker as Reference / Custom Ticker**: benchmark against the charted symbol or any symbol you specify.
- **Style**: text size, display size, box height, and per-cluster colors.

## Frequently Asked Questions

### Why do I sometimes get fewer clusters than requested?

K-means only forms groups it can genuinely distinguish. When several tickers share very similar coefficients, requested clusters collapse together, itself a clue that the basket is uniform.

### How is this different from a single correlation readout?

The [Correlation Coefficient](https://www.luxalgo.com/library/indicator/correlation-coefficient/) tracks one relationship through time. Correlation Clusters photographs ten at once and organizes them, which is what makes portfolio-level concentration visible in one panel.

### How do I access Correlation Clusters?

Free, via the LuxAlgo Library page. To experiment immediately, Quant, our coding agent, can run the tool directly from here. You can also copy the source code from this page and run it anywhere Pine Script® runs.

## Related indicators

- [Historical Correlation](https://www.luxalgo.com/library/indicator/historical-correlation/) (Correlation): markdown at https://www.luxalgo.com/library/indicator/historical-correlation.md
- [Sector Correlation Matrix](https://www.luxalgo.com/library/indicator/sector-correlation-matrix/) (Correlation): markdown at https://www.luxalgo.com/library/indicator/sector-correlation-matrix.md
- [Arbitrage Detector](https://www.luxalgo.com/library/indicator/arbitrage-detector/) (Correlation): markdown at https://www.luxalgo.com/library/indicator/arbitrage-detector.md
- [Arbitrage Matrix](https://www.luxalgo.com/library/indicator/arbitrage-matrix/) (Correlation): markdown at https://www.luxalgo.com/library/indicator/arbitrage-matrix.md
- [The Echo Forecast](https://www.luxalgo.com/library/indicator/the-echo-forecast/) (Correlation): markdown at https://www.luxalgo.com/library/indicator/the-echo-forecast.md
- [Correlated Sine Oscillator](https://www.luxalgo.com/library/indicator/correlated-sine-oscillator/) (Correlation): markdown at https://www.luxalgo.com/library/indicator/correlated-sine-oscillator.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
- [SuperTrend AI (Clustering)](https://www.luxalgo.com/library/indicator/supertrend-ai-clustering/) (K-means Regime Clustering): markdown at https://www.luxalgo.com/library/indicator/supertrend-ai-clustering.md

---

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