# Dynamic Time Warping Similarity

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

Searches history for the windows whose shape most resembles the last 30 bars, comparing z-normalized windows with dynamic time warping under a Sakoe-Chiba band. The closest non-overlapping analogs are boxed on the chart with optional aftermath zones showing what followed, ranked in a dashboard by DTW distance, with alerts when the best match crosses the strong-match threshold.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Jul 22, 2026.
- Access: free.
- Concepts: [Dynamic Time Warping Similarity](https://www.luxalgo.com/library/concept/dynamic-time-warping-similarity/) (primary)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=gxlrcjyjgas4otxyq8ym6jb4
- Page: https://www.luxalgo.com/library/indicator/dynamic-time-warping-similarity/

**Dynamic Time Warping Similarity** retrieves the historical price windows that most resemble the current one, using [dynamic time warping](https://www.luxalgo.com/library/concept/dynamic-time-warping-similarity/) so shapes that unfolded at different speeds can still match. It is the technique's first Library implementation. Every window is z-normalized, making the search about shape rather than price level, and the warping path is constrained to a Sakoe-Chiba band to keep alignments honest.

## How to Trade the Dynamic Time Warping Similarity?

- **Analog boxes**: the closest non-overlapping windows are boxed on the chart, colored from closest to farthest; labels report rank and DTW distance.
- **Aftermath zones**: dashed extensions show what happened after each analog, a study aid, explicitly not a forecast.
- **Strong match alerts**: fire when the best distance drops to or below the threshold, and when no analog remains that close.
- **Dashboard**: ranks the analogs by distance with their age in bars.

As elsewhere in the [machine learning family](https://www.luxalgo.com/library/family/machine-learning/), treat the output as evidence: a low distance says two shapes rhyme, nothing more.

## Dynamic Time Warping Similarity Settings

- **Source** (default close) and **Window Length** (default 30): the series and bars per window; the latest bars form the reference.
- **Search Lookback** (default 1000): historical bars scanned.
- **Scan Stride** (default 2): step between candidates; grows automatically to respect the computation budget.
- **Warping Band Width** (default 5): the Sakoe-Chiba constraint; 0 disables warping.
- **Analogs To Retrieve** (default 3): non-overlapping matches kept and ranked.
- **Strong Match Threshold** (default 3): the distance at or below which a match counts as strong.
- **Aftermath Zone** (default enabled) with **Length** (default 15): the highlighted bars after each analog.
- **Dashboard and style toggles**: panel position and size, labels, and colors.

## Frequently Asked Questions

### How is this different from a correlation measure?
The [Correlation Coefficient](https://www.luxalgo.com/library/indicator/correlation-coefficient/) compares two aligned series bar for bar, so identical shapes at different tempos score poorly. DTW searches over time alignments before measuring distance: what pattern retrieval at unknown tempo requires.

### Are the aftermath zones predictions?
No. They expose what followed each similar shape so the range of outcomes can be studied. Contradictory aftermaths are themselves information: the shape has no consistent historical resolution.

### Why did the scan skip some candidate windows?
The scan is budgeted: when lookback, window length and band width would exceed it, the stride increases automatically. A shorter window or lookback restores a denser scan.

## 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
- [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
- [Matrix Profile](https://www.luxalgo.com/library/indicator/matrix-profile/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/matrix-profile.md

---

Source: https://www.luxalgo.com/library/indicator/dynamic-time-warping-similarity/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
