-
Adapted from jdehorty on tradingview.
Nadaraya-Watson Kernel in dark green
Find it works on longer timeframes, 6 Hour etc.
Added an EMA filter (in aqua), to only take longs in uptrend, shorts downtrendOnce you have saved the command, this is an example of a script to trade from its signals:
local alpha = Input('Alpha', 2) local r = Input('Relative Weighting', 8) local h = Input('Lookback Window', 8) local x_0 = Input("Start Regression at Bar", 25) local emaFilter = Input('Use EMA Filter', false) local emaLength = Input('EMA Length', 200) local nwk = CC_Nadaraya_Watson_Kernel(alpha, r, h, x_0, emaFilter, emaLength) if nwk == SignalLong then DoLong() end if nwk == SignalShort then DoShort() end