This indicator builds upon the previously posted Nadaraya-Watson smoothers. Here we have created an envelope indicator based on Kernel Smoothing.
This tool can outline extremes made by the prices. This is achieved by estimating the underlying trend in the price, then calculating the mean absolute deviations from it, the obtained result is added/subtracted to the estimated underlying trend.
The non-repainting method estimates the underlying trend in price using an “endpoint Nadaraya-Watson estimator”, and would return similar results to more classical band indicators.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
//Nadaraya-Watson Envelope length = 21 //Window Size hh = 8 //Bandwidth mult = 2 once init = 1 src = customclose n = barindex If init = 1 then den = 0 For i = 0 to length-1 do $coefs[i]=exp(-(i*i)/(hh*hh*2)) den = den + $coefs[i] Next init = 0 Endif out = 0 For i = 0 to length-1 do out = out + src[i]*$coefs[i] Next out = out/den mae = exponentialAverage[length](abs(src-out)) * mult upper = out + mae lower = out - mae DRAWPOINT(barindex, lower, 2) coloured(0,255,0,200) DRAWPOINT(barindex, upper, 2) coloured(255,0,0,255) Return |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials