xmd79

Donchian RSI Bands

Nov 20th, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © DDMyke
  3.  
  4. //@version=5
  5. indicator(title="Donchian RSI Bands", shorttitle="dR$Ib", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
  6.  
  7. //Inputs
  8. src = input(ohlc4, "Source")
  9. rbdBC = input.bool(false, 'RSI Bollinger Band Barcolor', group='Barcolor')
  10. rcBC = input.bool(false, 'RSI Cloud Barcolor', group='Barcolor')
  11. dcBC = input.bool(false, 'Donchian Basis Barcolor', group='Barcolor')
  12.  
  13. showFrsi = input.bool(true, 'RSI', group='RSI')
  14. len = input.int(7, minval=1, title="Length", group='RSI')
  15. rsiUc = input(color.new(#00bcd4,0), title='Bullish Color', inline='rsi', group='RSI')
  16. rsiNc = input(color.new(#0c3299,0), title='Neutral Color', inline='rsi', group='RSI')
  17. rsiDc = input(color.new(#d930ff,0), title='Bearish Color', inline='rsi', group='RSI')
  18. rsiWidth = input.int(1, 'Line Width', minval=1, maxval=4, group='RSI')
  19. showDrsi = input.bool(false, 'RSI (Default Length)', inline='rsi2', group='RSI')
  20. rsi2C = input(color.new(#ffffff,50), title='Color', inline='rsi2', group='RSI' )
  21. showCloud = input(false, 'RSI Cloud', group='RSI')
  22. upCloud = input(color.new(#00bcd4,85), title='Bullish Cloud', inline='cloud', group='RSI')
  23. downCloud = input(color.new(#d930ff,85), title='Bearish Cloud', inline='cloud', group='RSI')
  24.  
  25. showBB = input.bool(true, 'Bollinger Bands', group='Double Bollinger Bands')
  26. length = input.int(35, 'Length', group='Double Bollinger Bands')
  27. mult2 = input.float(0.5, minval=0.5, step=0.25, maxval=5, title='Outer Band Deviation', group='Double Bollinger Bands')
  28. mult = input.float(0.25, minval=0.25, step=0.25, maxval=5, title='Inner Band Deviation', group='Double Bollinger Bands')
  29. offset = input.int(0, "Offset", minval = -500, maxval = 500, group='Double Bollinger Bands')
  30. bbandColor = input(color.new(#131722,20), title='Color', group='Double Bollinger Bands')
  31. showBBbasis = input.bool(true, 'Basis', group = 'Double Bollinger Bands')
  32. disp = input.float(0.1, 'Multiplier', minval=0.025, step=0.025, maxval=2, group='Double Bollinger Bands')
  33.  
  34. showDC = input.bool(true,'Donchian Channel', group='Donchian Channel')
  35. DClength = input.int(70, 'Length', group='Donchian Channel')
  36. DCwidth = input.int(5, 'Band Width', minval=1, maxval=20, group='Donchian Channel')
  37. dcUb = input(color.new(#00bcd4,85), title='Upper Band', inline='dcb', group='Donchian Channel')
  38. dcDb = input(color.new(#d930ff,85), title='Lower Band', inline='dcb', group='Donchian Channel')
  39. showDCB = input.bool(false,'Donchian Channel Basis', group='Donchian Channel')
  40. dcUc = input(color.new(#4caf50,0), title='Bullish Color', inline='dc', group='Donchian Channel')
  41. dcDc = input(color.new(#e91e63,0), title='Bearish Color', inline='dc', group='Donchian Channel')
  42.  
  43. //Calculations
  44. //RSI
  45. up = ta.rma(math.max(ta.change(src), 0), len)
  46. down = ta.rma(-math.min(ta.change(src), 0), len)
  47. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
  48. crsi = rsi
  49.  
  50. //RSI (Default Length)
  51. up2 = ta.rma(math.max(ta.change(src), 0), 14)
  52. down2 = ta.rma(-math.min(ta.change(src), 0), 14)
  53. rsi2 = down2 == 0 ? 100 : up2 == 0 ? 0 : 100 - (100 / (1 + up2 / down2))
  54. crsi2 = rsi2
  55.  
  56. //Double Bollinger Bands
  57. basis = ta.sma(rsi, length)
  58. dev = mult * ta.stdev(rsi, length)
  59. dev2 = mult2 * ta.stdev(rsi, length)
  60. upper = basis + dev
  61. upper2 = basis + dev2
  62. lower = basis - dev
  63. lower2 = basis - dev2
  64.  
  65.  
  66. //Basis Dispersion
  67. UpDisp = basis + (upper - lower) * disp
  68. DownDisp = basis - (upper - lower) * disp
  69. d1 = plot(showBBbasis and UpDisp ? UpDisp : na, color=color.new(#131722, 100), title='BB Basis Upper', linewidth=1, editable=false)
  70. d2 = plot(showBBbasis and DownDisp ? DownDisp : na, color=color.new(#131722, 100), title='BB Basis Lower', linewidth=1, editable=false)
  71.  
  72. //Donchian Channel
  73. upperdc = ta.highest(rsi,DClength)
  74. lowerdc = ta.lowest(rsi,DClength)
  75. basisdc = math.avg(upperdc, lowerdc)
  76.  
  77. //Plots
  78. rsiColor = rsi > upper2 ? rsiUc : rsi < lower2 ? rsiDc : rsiNc
  79. dcColor = rsi > basisdc ? dcUc : rsi < basisdc ? dcDc : na
  80. cloudFill = rsi > rsi2 ? upCloud : downCloud
  81. cloudColor = rsi > rsi2 ? rsiUc : rsiDc
  82.  
  83. barcolor(rbdBC ? rsiColor : na, editable=false)
  84. barcolor(dcBC ? dcColor : na, editable=false)
  85. barcolor(rcBC ? cloudColor : na, editable=false)
  86.  
  87. plot(showFrsi and rsi ? rsi : na, 'RSI', color=rsiColor, linewidth=rsiWidth, editable=false)
  88. c1 = plot(crsi, 'CRSI', color=color.new(#000000,100), editable=false)
  89. plot(showDrsi and rsi2 ? rsi2 : na, 'RSI (Default Length)', color=rsi2C, linewidth=1, editable=false)
  90. c2 = plot(crsi2, 'CRSI2', color=color.new(#000000,100), editable=false)
  91. p1 = plot(showBB and upper ? upper : na, 'Inner Upper Band', color=color.new(#2a2e39,100), offset=offset, editable=false)
  92. p2 = plot(showBB and upper2 ? upper2 : na, 'Outer Upper Band', color=color.new(#2a2e39,100), offset=offset, editable=false)
  93. p3 = plot(showBB and lower ? lower : na, 'Inner Lower Band', color=color.new(#2a2e39,100), offset=offset, editable=false)
  94. p4 = plot(showBB and lower2 ? lower2 : na, 'Outer Lower Band', color=color.new(#2a2e39,100), offset=offset, editable=false)
  95.  
  96. plot(showDC and upperdc ? upperdc : na, color=dcUb, title='Donchian Channel Upper Band', linewidth=DCwidth, editable=false)
  97. plot(showDC and lowerdc ? lowerdc : na, color=dcDb, title='Donchian Channel Lower Band', linewidth=DCwidth, editable=false)
  98. plot(showDCB and basisdc ? basisdc : na, 'Donchian Channel Basis', color=dcColor, linewidth=1, editable=false)
  99.  
  100. fill(p1,p2, color=bbandColor, title='Upper Band Fill', editable=false)
  101. fill(p3,p4, color=bbandColor, title='Upper Band Fill', editable=false)
  102. fill(d1, d2, color=showBBbasis ? bbandColor : na, title='BB Basis Fill', editable=false)
  103. fill(c1, c2, color=showCloud ? cloudFill : na, title='RSI Cloud Fill', editable=false)
  104.  
  105. hline(50, color=color.new(#ff8160,85), linewidth=1, linestyle=hline.style_dashed)
  106.  
  107.  
  108.  
  109.  
  110.  
Advertisement
Add Comment
Please, Sign In to add comment