# Matrix Profile

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

Computes a full matrix profile self-join over the last 400 bars: every 24-bar window's z-normalized distance to its nearest neighbor elsewhere in the sample, drawn as a companion series where valleys are repeated shapes and peaks are anomalies. Motif pairs and discords are boxed on the price chart, the newest window is paired with its closest analog, and three alerts flag motif matches, discords and the top anomaly.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Apr 28, 2026.
- Access: free.
- Concepts: [Matrix Profile](https://www.luxalgo.com/library/concept/matrix-profile/) (primary)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=wfrvmlz1jzgno02vijp82jlj
- Page: https://www.luxalgo.com/library/indicator/matrix-profile/

**Matrix Profile** brings genuine all-pairs shape search to the chart, the first faithful implementation of the [matrix profile](https://www.luxalgo.com/library/concept/matrix-profile/) in the library. Every 24-bar window of the last 400 bars is compared against every other, and each window's z-normalized distance to its nearest neighbor draws as a companion series: valleys are shapes that recurred, peaks are stretches unlike anything else in the sample, zero an exact repeat.

## How to Trade the Matrix Profile?

- **Motifs (M1, M2)**: the lowest profile points extract as window pairs, boxed on the price chart: evidence a shape repeated, never that it predicts.
- **Discords (D1)**: the highest points mark windows with no good match anywhere, anomalies worth review as regime breaks, data errors or event reactions.
- **Current window match**: the newest window and its nearest historical neighbor are outlined together, an analog pre-filter to re-rank with the finer [machine learning tools](https://www.luxalgo.com/library/family/machine-learning/).

## Matrix Profile Settings

- **Source** (default close) and **Use First Differences** (off): the series analyzed; differences match movement shape, not level path.
- **Window Length (m)** (default 24): the scale of the shapes the profile can find.
- **Analysis Bars (n)** (default 400): the sample the self-join scans.
- **Exclusion Zone (x m)** (default 0.5): half-width of the skip zone suppressing trivial self-matches.
- **Motif Pairs** (default 2) and **Discords** (default 1): extremes to extract, spaced an exclusion zone apart.
- **Motif Percentile** (default 10.0) and **Discord Percentile** (default 90.0): the dashed guide levels and alert thresholds for the newest window.
- Display: **Current Window Match**, **Mark Motifs & Discords On Chart**, **Percentile Guides** and **Show Dashboard** (all on), **Profile Width** (default 2).

## Frequently Asked Questions

### How does this differ from autocorrelation?

[Autocorrelation](https://www.luxalgo.com/library/indicator/autocorrelation/) measures whether the whole series correlates with a lagged copy of itself: one number per lag, averaged over everything. The matrix profile localizes repetition: which specific windows repeated, where their twins sit, and which stretch matches nothing.

### Why are the distances z-normalized?

Each window is rescaled to zero mean and unit variance before comparison, so matches register shape, not price level or volatility regime. A quiet consolidation and a violent one with the same silhouette count as the same motif.

### Does the profile update as new bars arrive?

Yes. The entire self-join recomputes on the latest bar over the rolling sample, so the drawings describe the current stretch of history rather than accumulating bar by bar: a live snapshot of the last n bars.

## Related indicators

- [KNN Supertrend Horizon](https://www.luxalgo.com/library/indicator/knn-supertrend-horizon/) (kNN Analog Forecasting): markdown at https://www.luxalgo.com/library/indicator/knn-supertrend-horizon.md
- [kNN Market Architecture](https://www.luxalgo.com/library/indicator/knn-market-architecture/) (kNN Analog Forecasting): markdown at https://www.luxalgo.com/library/indicator/knn-market-architecture.md
- [Dynamic Time Warping Similarity](https://www.luxalgo.com/library/indicator/dynamic-time-warping-similarity/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/dynamic-time-warping-similarity.md
- [The Echo Forecast](https://www.luxalgo.com/library/indicator/the-echo-forecast/) (kNN Analog Forecasting): markdown at https://www.luxalgo.com/library/indicator/the-echo-forecast.md
- [Indicator Configuration Forecasting](https://www.luxalgo.com/library/indicator/indicator-configuration-forecasting/) (kNN Analog Forecasting): markdown at https://www.luxalgo.com/library/indicator/indicator-configuration-forecasting.md
- [MACD Based Price Forecasting](https://www.luxalgo.com/library/indicator/macd-based-price-forecasting/) (kNN Analog Forecasting): markdown at https://www.luxalgo.com/library/indicator/macd-based-price-forecasting.md
- [Neighboring Trailing Stop](https://www.luxalgo.com/library/indicator/neighboring-trailing-stop/) (kNN Analog Forecasting): markdown at https://www.luxalgo.com/library/indicator/neighboring-trailing-stop.md
- [Historical Price Projection](https://www.luxalgo.com/library/indicator/historical-price-projection/) (kNN Analog Forecasting): markdown at https://www.luxalgo.com/library/indicator/historical-price-projection.md

---

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