I like this indicator with just the long/short arrows only. I revamped the code (hopefully this is ok) to show arrows only and made the cyan to distinguish from other arrows I have in place. Asa day trader I only use the 1min/5min charts and haven't tried it on longer time frames. Here is the code change:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.
#// The non-repainting implementation of Nadaraya–Watson Regression using a Rational Quadratic Kernel is an original idea from @jdehorty i added the upper band an lower band using ATR, with this
#// we get an aproximation of Nadaraya-Watson Envelope
#indicator('Nadaraya-Watson non repainting', overlay=true, timeframe="")
# Converted and mod by Sam4Cok@Samer800 - 10/2022
# v2.0 Add 2 methods of calculating NW. Both non repating.
# v2.5 Added super NW. All calc typs are non repating - 11 / 2022.
# v3.0 Some code fixes, change on band style and added option for signal wait bar - 11/2022
#Revamped by Charles Ricks to show trend arrows only 2/10/23
input src = close;
input SmaplePeriod = 50;
input NadarayaType = {default Quadratic, Lux, Super};
input SignalStyle = {Default Bubbles, Arrows, None};
input LookbackWindow = 8; # The number of bars used for the estimation. Recommended range: 3-50
input RelativeWeighting = 8.0; # Relative weighting of time frames. Recommended Range: 0.25-25
input RegressionStartBar = 25; # Bar index on which to start regression. Recommended range: 5-25
input ColorLag = 1; # This often results in less color transitions overall.
input SignalLag = 3; # Lag for crossover detection. Lower values result in earlier crossovers.
input AtrPeriod = 60; # ATR Period
input MultiForNearBand = 1.5; # Multiplier for near band.
input MultiForFarBand = 7.0; # Multiplier for far band.
input smoothing = no;
input smoothLength = 3;
def na = Double.NaN;
def h = high;
def l = low;
def CalcType = if NadarayaType==NadarayaType.Quadratic then 1 else
if NadarayaType==NadarayaType.Lux then 2 else 0;
def CalcPeriod = min(SmaplePeriod + 500, 750);
def Sample = min(SmaplePeriod, 500);
def size = if CalcType==0 then sample else CalcPeriod;
def style= if SignalStyle.Bubbles then 1 else
if SignalStyle.Arrows then -1 else 0;
#kernel_atr(length, _high, _low, _close) =>
script kernel_atr {
input length = 60;
input _high = high;
input _low = low;
input _close = close;
def tr = if isNaN(_high[1]) then _high - _low else TrueRange(_high,_close,_low);
plot kATR = WildersAverage(tr, length);
}
#-- counter
script counter {
input length = 500;
input Bandwidth = 8;
def counter = fold i = 0 to length - 1 with p do
p + Exp(-(Power(i,2)/(Bandwidth*Bandwidth*2)));
plot result = counter;
}
#super(src, len) =>
script super {
input src = close;
input len = 50;
def f = (1.414 * Double.Pi)/len;
def a = exp(-f);
def c2 = 2 * a * cos(f);
def c3 = -a * a;
def c1 = 1 - c2 - c3;
def smooth;
smooth = c1 * (src+src[1]) * 0.5 + c2 * (smooth[1]) + c3 * (smooth[2]);
plot return = smooth;
}
#kernel_regression1(_src, _size, LookbackWindow, RegressionStartBar, RelativeWeighting) =>
script kernel {
input _src = close;
input _size = 500;
input _h = 8;
input x_0 = 2;
input r = 8;
def _currentWeight;
def _cumulativeWeight;
_currentWeight = fold i = 0 to _size + x_0 with p do
p + GetValue(_src, i) * Power(1 + (Power(i, 2) / ((Power(_h, 2) * 2 * r))), -r);
_cumulativeWeight = fold j = 0 to _size + x_0 with q do
q + Power(1 + (Power(j, 2) / ((Power(_h, 2) * 2 * r))), -r);
plot currentWeight = _currentWeight / _cumulativeWeight;
}
script Lux {
input src = close;
input size = 500;
input LookbackWindow = 8;
def sum;
def sumw;
def y2;
def Bandwidth = LookbackWindow;
sum = fold j = 0 to size-1 with p do
p + src[j] * Exp(-(Power(counter(size, Bandwidth)-j,2)/(Bandwidth*Bandwidth*2)));
sumw = fold k = 0 to size-1 with q do
q + Exp(-(Power(counter(size,Bandwidth)-k,2)/(Bandwidth*Bandwidth*2)));
y2 = sum/sumw;
plot YNW = y2;
}
# //----Type 1 Calc
def kerSrc1 = kernel(src, size, LookbackWindow, RegressionStartBar, RelativeWeighting);
def kerHi1 = kernel(h, size, LookbackWindow, RegressionStartBar, RelativeWeighting);
def kerLo1 = kernel(l, size, LookbackWindow, RegressionStartBar, RelativeWeighting);
def nwHigh1 = if !Smoothing then kerHi1 else WMA(kerHi1, smoothLength);
def nwLow1 = if !Smoothing then kerLo1 else WMA(kerLo1, smoothLength);
def nwSrc1 = if !Smoothing then kerSrc1 else WMA(kerSrc1, smoothLength);;
# //--- Type 2 Calc
def luxSrc2 = Lux(src, size, LookbackWindow);
def luxHigh2 = Lux(h,size, LookbackWindow);
def luxLow2 = Lux(l,size, LookbackWindow);
def nwHigh2 = if !Smoothing then luxHigh2 else WMA(luxHigh2,smoothLength);
def nwLow2 = if !Smoothing then luxLow2 else WMA(luxLow2,smoothLength);
def nwSrc2 = if !Smoothing then luxSrc2 else WMA(luxSrc2,smoothLength);
# //------Type3 Calc
def SupHi3 = super(h, size);
def SupLo3 = super(l, size);
def SupSrc3 = super(src, size);
def nwHigh3 = if !Smoothing then SupHi3 else WMA(SupHi3, smoothLength);
def nwLow3 = if !Smoothing then SupLo3 else WMA(SupLo3, smoothLength);
def nwSrc3 = if !Smoothing then SupSrc3 else WMA(SupSrc3, smoothLength);
#// Plot
def KernelHi = if CalcType == 1 then nwHigh1 else
if CalcType == 2 then nwHigh2 else nwHigh3; # Nadaraya-Watson Estimate - High
def KernelLo = if CalcType == 1 then nwLow1 else
if CalcType == 2 then nwLow2 else nwLow3; # Nadaraya-Watson Estimate - Low
def KernelEst =if CalcType == 1 then nwSrc1 else
if CalcType == 2 then nwSrc2 else nwSrc3; # Nadaraya-Watson Estimate - src
#// Trend
def isBullish = KernelEst > KernelEst[1];
def isBearish = KernelEst < KernelEst[1];
def isBullishCount = if isBullish then isBullishCount[1] + 1 else 0;
def isBearishCount = if isBearish then isBearishCount[1] + 1 else 0;
def isBullishCross = isBullishCount>=ColorLag;
def isBearishCross = isBearishCount>=ColorLag;
#--- Band Cals
def nATR = kernel_atr(AtrPeriod, KernelHi, KernelLo, KernelEst);
def _upper_far = KernelEst + MultiForFarBand * natr;
def _upper_near = KernelEst + MultiForNearBand * natr;
def _lower_near = KernelEst - MultiForNearBand * natr;
def _lower_far = KernelEst - MultiForFarBand * natr;
def _upper_avg = (_upper_far + _upper_near) / 2;
def _lower_avg = (_lower_far + _lower_near) / 2;
def upMid = _upper_avg;
def loMid = _lower_avg;
#----- Signal
def SigU = src > loMid;
def SigD = src < upMid;
def SigUCount = if SigU then SigUCount[1] + 1 else 0;
def SigDCount = if SigD then SigDCount[1] + 1 else 0;
def SigUp = SigU and SigUCount== SignalLag;
def SigDn = SigD and SigDCount== SignalLag;
plot ArrowUp = if (SigUp and style<0) then l else na;
plot ArrowDn = if (SigDn and style<0) then h else na;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowUp.SetDefaultColor(Color.Cyan);
ArrowDn.SetDefaultColor(Color.Cyan);