# Nadaraya-Watson Envelope

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

Wraps a kernel-regression estimate of the underlying trend in bands offset by mean absolute deviation, flagging stretched prices for contrarian trading. Triangles and alerts fire when price crosses an envelope extremity, and a non-repainting endpoint mode makes it behave like a traditional band indicator; the default smoothing repaints by design.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Oct 18, 2021.
- Access: free.
- Concepts: [Kernel Regression](https://www.luxalgo.com/library/concept/kernel-regression/) (primary), [Envelope](https://www.luxalgo.com/library/concept/envelope/)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=cmpwn408w005lvhsgcp9oppla
- Page: https://www.luxalgo.com/library/indicator/nadaraya-watson-envelope/

**Nadaraya-Watson Envelope** estimates the underlying price trend with [kernel regression](https://www.luxalgo.com/library/concept/kernel-regression/) and builds an [envelope](https://www.luxalgo.com/library/concept/envelope/) around the fit by adding and subtracting mean absolute deviations. Crossings of the upper or lower extremity print triangles and can trigger alerts, giving contrarian traders a systematic cue that price has stretched unusually far from its estimated center.

Two calculation modes are offered. The default smoothing recalculates the fit across the window and therefore repaints; the alternative uses an endpoint Nadaraya-Watson estimator that does not, delivering results akin to traditional band indicators. In the default mode the triangles are redrawn from the latest fit too, so they show past crossings in hindsight; in the endpoint mode, triangles print as each crossing happens and stay fixed once the bar closes.

## How to Trade the Nadaraya-Watson Envelope?

- **Price crosses the upper extremity**: an unusually stretched advance relative to the estimated trend. Contrarian setups look for rotation back toward the center.
- **Price crosses the lower extremity**: the mirror case, flagging stretched declines for mean-reversion longs.
- **Triangle labels**: in the endpoint mode they mark each crossing as it happens and stay on their bar once it closes, which is what makes them usable in real time; in the default repainting mode they are redrawn from the latest fit and show crossings in hindsight.

A note on expectations: extremity crossings describe stretch, not guaranteed reversals, and nothing suggests this envelope outperforms traditional band tools. Treat it as a single input within a broader plan rather than a standalone system.

## Nadaraya-Watson Envelope Settings

- **Bandwidth**: controls the smoothness of the envelopes; higher values produce smoother results.
- **Mult**: sets the width of the envelope.
- **Source**: the input series used for calculation.
- **Repainting Smoothing**: chooses between the repainting fit and the non-repainting endpoint method.

## Frequently Asked Questions

### Does the Nadaraya-Watson Envelope repaint?
With the default settings, yes: the kernel fit is recomputed over the window as new bars arrive. Switch Repainting Smoothing to the endpoint method and the indicator stops repainting, behaving like a conventional band tool.

### How does it relate to the Nadaraya-Watson Smoothers?
It is built directly on them: the [Nadaraya-Watson Smoothers](https://www.luxalgo.com/library/indicator/nadaraya-watson-smoothers/) plot the kernel fit itself, while this tool wraps deviation-based bands around that fit and adds the extremity-crossing triangles and alerts.

### What does it cost to use the Nadaraya-Watson Envelope?
Nothing: it ships free in the LuxAlgo Library, and you can compare the repainting and endpoint modes by running it in Quant, our coding agent, via this page. You can also copy the source code from this page and run it anywhere Pine Script® runs.

## Related indicators

- [Nadaraya-Watson Smoothers](https://www.luxalgo.com/library/indicator/nadaraya-watson-smoothers/) (Kernel Regression): markdown at https://www.luxalgo.com/library/indicator/nadaraya-watson-smoothers.md
- [Machine Learning: Gaussian Process Regression](https://www.luxalgo.com/library/indicator/machine-learning-gaussian-process-regression/) (Kernel Regression): markdown at https://www.luxalgo.com/library/indicator/machine-learning-gaussian-process-regression.md
- [Machine Learning: Anchored Gaussian Process Regression](https://www.luxalgo.com/library/indicator/machine-learning-anchored-gaussian-process-regression/) (Kernel Regression): markdown at https://www.luxalgo.com/library/indicator/machine-learning-anchored-gaussian-process-regression.md
- [Whittaker Envelope](https://www.luxalgo.com/library/indicator/whittaker-envelope/) (Envelope): markdown at https://www.luxalgo.com/library/indicator/whittaker-envelope.md
- [Proximal Range Filter](https://www.luxalgo.com/library/indicator/proximal-range-filter/) (Envelope): markdown at https://www.luxalgo.com/library/indicator/proximal-range-filter.md
- [Gaussian Volume Profile](https://www.luxalgo.com/library/indicator/gaussian-volume-profile/) (Kernel Density Estimation): markdown at https://www.luxalgo.com/library/indicator/gaussian-volume-profile.md
- [KDE Value Clouds](https://www.luxalgo.com/library/indicator/kde-value-clouds/) (Kernel Density Estimation): markdown at https://www.luxalgo.com/library/indicator/kde-value-clouds.md
- [Structural SVM Ranker](https://www.luxalgo.com/library/indicator/structural-svm-ranker/) (Support Vector Machines): markdown at https://www.luxalgo.com/library/indicator/structural-svm-ranker.md

---

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