Back to Guides
Guide

Does the Nadaraya-Watson Envelope Repaint? What It Costs

Does the Nadaraya-Watson envelope repaint? Yes by default: the fit is recomputed as new bars arrive, so the chart you review is not the one you traded.

Yes, if you loaded the popular one. Its default mode recalculates the whole fit every time a new bar arrives, which means the line and the bands you are looking at today are not the ones that were on the chart last week.

A second, different indicator is published under the same name and does not repaint. That is why the question gets answered both ways so often: people are describing two different tools. What the repainting costs you is that a crossing you watched print in real time may not be a crossing on the chart you open later, while the marker it left behind stays where it was.

Two indicators share one name

The one most people mean is LuxAlgo's Nadaraya-Watson Envelope. It fits a kernel regression line through the window and, in its own words, builds "an envelope around the fit by adding and subtracting mean absolute deviations". Its settings are Bandwidth, Mult, Source and Repainting Smoothing.

The other is jdehorty's Nadaraya-Watson Envelope (Non-Repainting). It uses a Rational Quadratic kernel, and its bands come from something else: "a custom ATR calculated from the kernel estimations for the high, low, and close series". It plots two upper and two lower bands rather than one pair.

The LuxAlgo envelopeThe non-repainting envelope
KernelGaussian smootherRational Quadratic
Bands fromMean absolute deviation of the fitAn ATR of the kernel's own high, low and close estimates
Band countOne upper, one lowerTwo upper, two lower
Repaints by defaultYesNo
Settings namedBandwidth, Mult, Source, Repainting SmoothingLookback Window, Relative Weighting, Start Regression at Bar, ATR Length, Near and Far ATR factors

Neither is the "real" one. They are different indicators, and a reader comparing notes with someone on the other one is not comparing like with like.

Does the Nadaraya-Watson envelope repaint?

The LuxAlgo one does, by default, and its own documentation says so plainly: "With the default settings, yes: the kernel fit is recomputed over the window as new bars arrive." Switching Repainting Smoothing to the endpoint method stops it. A release in July 2023 added that full non-repainting option, by popular request.

The author's defence is half right. Triangles mark each crossing when it happens and stay anchored where they first appeared, "even if the cross is no longer visible after a recalculation of the envelope". So the marker is a permanent record. The chart underneath it is not, which means your markers keep saying a crossing happened at a level the bands have since moved away from.

What does the repainting actually cost you?

The cost is that the chart you review is not the chart you traded. One is the chart as it stood when each bar closed, with the fit and the bands that existed then. The other recomputes the fit over the whole window when you open it later, so a bar can sit outside the bands on one and inside them on the other.

That leaves a chart disagreeing with the record it carries. The triangles sit where crossings printed, the bands sit where the last recalculation put them, and nothing on the chart tells you which triangles still have a crossing underneath.

How much of that survives depends on the bandwidth, the multiplier and the timeframe you are on. Step through your own history with the next bar hidden and you can count it on the market you trade.

What is the Nadaraya-Watson envelope formula?

The envelope is a weighted average of prices, where the weight falls off with distance in bars. Each bar's fitted value is the sum of every price in the window multiplied by its weight, divided by the sum of the weights. The kernel is the weighting function, and the bandwidth controls how fast the weight falls away.

The two kernels in use are published by scikit-learn, which defines them. The Gaussian, or RBF:

k(d) = exp(-d^2 / (2 * l^2))

And the Rational Quadratic:

k(d) = (1 + d^2 / (2 * alpha * l^2))^(-alpha)

Here d is the distance in bars, l is the bandwidth, and alpha is what the trading ports call Relative Weighting. scikit-learn describes the Rational Quadratic as "a scale mixture (an infinite sum) of RBF kernels", which is why the two converge. jdehorty's KernelFunctions library, which the non-repainting version is built on, says it outright: "As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel."

That convergence is a limit, not a description of the settings anyone trades at: at the Relative Weighting values the ports suggest, the two kernels are still different functions.

The bands are the second half of the formula, and this is where the two indicators part company. One adds and subtracts a multiple of the mean absolute deviation between price and the fit, which gives a single width for the whole window. The other builds an ATR from the kernel's own estimates of high, low and close, which breathes. One width holds across the whole window while the other changes bar by bar, so the two sets of bands sit at different distances from the same fit and do not flag the same extremities.

What are the best settings for the Nadaraya-Watson envelope?

Neither author publishes a numeric default for anything.

Abir Pathak's third-party MT4 and MT5 port does publish a parameter set, and it is sorted by trading style and timeframe rather than by appetite for risk. Its day-trading set, the one it calls balanced settings for intraday moves, is Lookback Window 8 to 12, Relative Weighting 8.0, Start Regression at Bar 25, ATR Length 60, Near ATR Factor 1.5, Far ATR Factor 2.0. Its scalping set, for the fastest charts, uses Relative Weighting 3.0 to 5.0 with a shorter window and tighter bands, and its swing set, for the slowest, uses 10.0 to 15.0 with a longer window and wider bands. Those are that port's choices, not the indicators' defaults.

Relative Weighting is not a cosmetic knob. It is the alpha in the Rational Quadratic, so moving it across the span those three sets cover, from 3.0 to 15.0, changes how fast the weight falls away and moves the fitted line with it. Bandwidth matters more again, since it sets how many bars have any say at all.

Pick the non-repainting mode first, so you are at least testing something stable, then change one setting at a time and write down each setting you tried.

Nadaraya-Watson envelope vs Bollinger Bands

Both are a centre line with deviation bands either side. The two differences are the weighting and whether the centre line can revise itself.

Bollinger Bands put a simple moving average down the middle, where every bar in the lookback counts the same and the line never changes once a bar has closed. The Nadaraya-Watson envelope weights nearby bars more heavily, which makes a smoother and more responsive centre, and in its default mode buys that smoothness by revising bars after the fact. Bollinger's standard deviation bands widen and narrow with volatility; the deviation version of this envelope holds one width across its window.

So if you want a centre line that cannot revise itself after the fact, Bollinger already gives you one.

How do you test a Nadaraya-Watson rule by hand?

Write the rule down before you load anything, because a repainting indicator will otherwise write it for you after the fact. A rule you can check names the mode, the bandwidth, the multiplier, what counts as a crossing, and what you do about it.

Then step forward one bar at a time with the next bar hidden, which is how you see what the envelope actually showed you rather than what it shows you now. LuxAlgo says of its tool that crossings "describe stretch, not guaranteed reversals". The author says so on the original publication too: "We do not have data supporting the performance of this tool over more classical bands/envelope/channels indicators." We do not have data either way.

ChartLabs has the LuxAlgo construction built in, as Nadaraya-Watson Envelope in the Indicators menu, under Standard. On the question this article is about, it departs from LuxAlgo's default: its Mode setting defaults to Endpoint, which never changes a value already drawn on a closed bar. Redrawing is there if you want to compare, and while it is on, every line in the legend is marked "(redraws)". The other defaults are Bandwidth 8 and Multiplier 3, on the close. The ATR-based non-repainting version is not built in. The testing is manual, which for this subject is the point. Step through history bar by bar with the future hidden, and every trade keeps a snapshot of your drawings, indicators and chart state at the moment you entered, so a crossing you acted on stays attached to the chart as it looked then, not as it looks once later bars have rewritten it.

Where to go next

Backtesting a Trading Strategy covers the workflow, Forex Backtesting the data and session side, and Manual vs Automated Backtesting covers which half of this you would want to automate.

Then pick one mode, one bandwidth and one multiplier, and step through a year of it. ChartLabs is $20 a month or $200 a year, one plan, and the trial is 7 days with no credit card: start the free trial.

Related Topics

nadaraya-watson-envelopekernel-regressionrepainting-indicatorsindicatorsmanual-backtesting