Add some extra spaces to Donchian Channel that helps to avid Stoplosses

Viewed 24

I need to add some ticks in Donchian Channel but getting to an issue that avoids the candles to cut the channel if the highs increase or lows decrease by the amount lower the the amount of ticks i have increased the Channel with.

I wrote this code but if a candle doesnt give significant move the donchian channel wont give a crossover.

//@version=5

indicator('DC Offset', shorttitle='Donchian Channel Offset', overlay=true, timeframe = "")

DClength = input(21, title="Donchian Channel length")
DCoffset = input.int(1, title="[DCoffset]", minval=0, maxval=3)

dcd = close < 100 ? 1 :
 close >= 100  and close < 250  ?  5 :
 close >= 250  and close < 1000 ? 10 :
 close >= 1000 and close < 5000 ? 40 :
 close >= 5000 ? 40 : 
 input(5, "DC Difference", group = "DC")

    

dch = syminfo.mintick*dcd
dcu = (ta.highest(high, DClength)[DCoffset] + dch)
dcl = (ta.lowest(low, DClength)[DCoffset] - dch)
// DC

Basis = math.avg(dcu, dcl)

ubP = plot(dcu, title='Upper', style=plot.style_line, color=color.new(color.green, 0), linewidth=2)
lbP = plot(dcl, title='Lower', style=plot.style_line, color=color.new(color.red, 0), linewidth=2)
mbP = plot(Basis, title='Basis', style=plot.style_line, color=color.new(color.silver, 0), linewidth=2, display = display.none)
fill(ubP, lbP, color=color.rgb(33, 150, 243, 95), title='Background', display = display.none)
0 Answers
Related