RicardoSantos

[RS]JR Flex Donchian Channel V0R1

Experimental:
Request for JR, fixed some stuff...
erroneous functions using highest() when it should be lowest()
missing midline...
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
study("[RS]JR Flex Donchian Channel V0R1", overlay=true)
BB_Length = input(title='BB Length', type=integer, defval=10)
BB_Deviations = input(title='BB Deviations', type=integer, defval=2)
BB_Src = input(title='Source', type=source, defval=close)
//  ||---   BB
BB_Midline = sma(BB_Src, BB_Length)
BB_Deviation = stdev(BB_Src, BB_Length) * BB_Deviations
BB_Upper = BB_Midline + BB_Deviation
BB_Lower = BB_Midline - BB_Deviation
//  ||---   BBW
BB_Width = ((BB_Upper-BB_Lower) / BB_Midline)
//  ||---   DC
DC_Upper = BB_Width <= .025 ? highest(49) :
        BB_Width > .025 and BB_Width <= .050 ? highest(40) :
        BB_Width > .050 and BB_Width <= .075 ? highest(30) :
        BB_Width > .075 and BB_Width <= .100 ? highest(20) :
        BB_Width > .100 and BB_Width <= .125 ? highest(10) :
        BB_Width > .125 and BB_Width <= .150 ? highest(7) :
        BB_Width > .150 ? highest(3) : highest(2)

DC_Lower = BB_Width <= .025 ? lowest(49) :
        BB_Width > .025 and BB_Width <= .050 ? lowest(40) :
        BB_Width > .050 and BB_Width <= .075 ? lowest(30) :
        BB_Width > .075 and BB_Width <= .100 ? lowest(20) :
        BB_Width > .100 and BB_Width <= .125 ? lowest(10) :
        BB_Width > .125 and BB_Width <= .150 ? lowest(7) :
        BB_Width > .150 ? lowest(3) : lowest(2)

pU = plot(DC_Upper, color=blue)
pL = plot(DC_Lower, color=blue)
pM = plot(avg(DC_Upper, DC_Lower), color=black)
fill(pU, pM, color=olive, transp=70)
fill(pL, pM, color=orange, transp=70)