TradingView
jdehorty
22. Sept. 2022 11:23

Nadaraya-Watson: Rational Quadratic Kernel (Non-Repainting) 

Ethereum / TetherKuCoin

Beschreibung

What is Nadaraya–Watson Regression?
Nadaraya–Watson Regression is a type of Kernel Regression, which is a non-parametric method for estimating the curve of best fit for a dataset. Unlike Linear Regression or Polynomial Regression, Kernel Regression does not assume any underlying distribution of the data. For estimation, it uses a kernel function, which is a weighting function that assigns a weight to each data point based on how close it is to the current point. The computed weights are then used to calculate the weighted average of the data points.

How is this different from using a Moving Average?
A Simple Moving Average is actually a special type of Kernel Regression that uses a Uniform (Retangular) Kernel function. This means that all data points in the specified lookback window are weighted equally. In contrast, the Rational Quadratic Kernel function used in this indicator assigns a higher weight to data points that are closer to the current point. This means that the indicator will react more quickly to changes in the data.

Why use the Rational Quadratic Kernel over the Gaussian Kernel?
The Gaussian Kernel is one of the most commonly used Kernel functions and is used extensively in many Machine Learning algorithms due to its general applicability across a wide variety of datasets. The Rational Quadratic Kernel can be thought of as a Gaussian Kernel on steroids; it is equivalent to adding together many Gaussian Kernels of differing length scales. This allows the user even more freedom to tune the indicator to their specific needs.
The formula for the Rational Quadratic function is:
K(x, x') = (1 + ||x - x'||^2 / (2 * alpha * h^2))^(-alpha)
where x and x' data are points, alpha is a hyperparameter that controls the smoothness (i.e. overall "wiggle") of the curve, and h is the band length of the kernel.

Does this Indicator Repaint?
No, this indicator has been intentionally designed to NOT repaint. This means that once a bar has closed, the indicator will never change the values in its plot. This is useful for backtesting and for trading strategies that require a non-repainting indicator.

Settings:
  • Bandwidth. This is the number of bars that the indicator will use as a lookback window.
  • Relative Weighting Parameter. The alpha parameter for the Rational Quadratic Kernel function. This is a hyperparameter that controls the smoothness of the curve. A lower value of alpha will result in a smoother, more stretched-out curve, while a lower value will result in a more wiggly curve with a tighter fit to the data. As this parameter approaches 0, the longer time frames will exert more influence on the estimation, and as it approaches infinity, the curve will become identical to the one produced by the Gaussian Kernel.
  • Color Smoothing. Toggles the mechanism for coloring the estimation plot between rate of change and cross over modes.

Versionshinweise

Added paper for those that may be interested in reading more.

Versionshinweise

  • Added alarms for color changes due to popular request
  • Added option to specify starting index of regression
  • Added additional reading reference regarding the Rational Quadratic Kernel for those that are interested
  • Minor refactoring to make code more readable

Versionshinweise

  • Further code simplifications and minor refactoring for clarity

Versionshinweise

Added an alert stream for those wishing to backtest by feeding the source into another indicator (e.g., Zendog v3). Use -1 value for Bearish Signal and 1 for Bullish Signal.
Kommentare
veryfid
Very nice
jdehorty
@veryfid Thanks for your support. :)
ThousandWishes
@jdehorty, Hopefully it is genuinely not repainting. TQ to the writer for his efforts.
WallStreetKwt
Love it
boserranof1976
This indicator is great, but in some occasions it does not send alerts even though the color changed. I am using close and candle close variables. Smooth color lag 2, Chart timeframe: 1 min, indicator timeframe 30 second, source close, alerts send after candle close. So far catches every price action move with big wins and small losses. Just wish you could find the way of making the alerts more reliable. Amazing work !
krishw48
pls add buy sell arrows
chimera_brendo
Nice one! I had tried something similar recently but my signal result was not as clean as what you've produced.
I'm not sure if I read part of your description incorrectly, but it looks like you've made a typo here including "lower" when you may have meant "higher":
(I've pointed out these in rounded brackets)

"A (lower) value of alpha will result in a smoother, more stretched-out curve, while a (lower) value will result in a more wiggly curve with a tighter fit to the data"
jdehorty
@chimera_brendo Thanks for pointing this out; that is indeed a typo. It won't allow me to edit the description anymore, but the second "lower" should be "higher":

"A lower value of alpha will result in a smoother, more stretched-out curve, while a *higher* value will result in a more wiggly curve with a tighter fit to the data."

The key idea is that the RQ-kernel can be thought of as a summation of multiple Gaussian kernels of different length scales, and you can make the longer length scales count for more when you decrease the value of alpha (aka: the "Relative Weighting" parameter in the Settings menu).

Using an alpha value of infinity will be equal to using a Gaussian kernel at a specific length scale, but in practice, you will barely notice a notice a difference for alpha values greater than 25 since they rapidly converge to values that are approximately equal to the solution when alpha equals infinity.

Conversely, using an alpha value of zero will effectively render the specified length scale irrelevant (e.g. a "Lookback Window" value of 3 will result in the same curve as a "Lookback Window" value of 300). Thus, with very small values of alpha that approach 0, the overall estimation is almost purely a function of the total amount of bars used in the regression, which you can tweak using the "Start Regression at Bar" setting.

I hope this helps clarify any confusion. Please don't hesitate to let me know if you spot any other discrepancies or have any other further questions.
Private_Traders
@jdehorty, sir In my view your are a Super human because Machine learning indecator made public. if some newbie trader blindly follow it He can be a profitable trader.

Your point: 96 +
LuxAlgo point: 65-70
CihanCrypto
Thank you so much for this really great indicator based on our loved Nadaraya-Watson. Is that also possible to have alerts for this indicator as well? This will be really great.
Mehr