xmd79

Donchian RSI Bands

Nov 22nd, 2021
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.12 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. //end of this part
  109.  
  110. //@version=5
  111. //indicator(title='Multi Time RSI', overlay=false)
  112.  
  113. avg1 = input(title='Slow Average :', defval=21)
  114. avg2 = input(title='Fast Average :', defval=11)
  115. rsi_avg_step = input(title='RSI Avg Step :', defval=1.0)
  116.  
  117. //inp = input(close)
  118.  
  119.  
  120. //Plot RSI
  121. rsiCurrent = ta.rsi(src, 11)
  122. rsi_current_plot = plot(rsiCurrent, color=color.new(color.black, 0), linewidth=2, style=plot.style_line, title='Current RSI Time Frame')
  123.  
  124. rsi_avg = ta.ema(ta.rsi(src, 11), avg1)
  125. rsi_avg_plot = plot(rsi_avg, color=color.new(color.red, 0), linewidth=2, style=plot.style_line, title='Current AVG RSI Time Frame')
  126. rsi_avg_1 = ta.ema(ta.rsi(src, 11), avg2)
  127. rp1 = plot(rsi_avg_1, color=color.new(color.blue, 50), linewidth=1, style=plot.style_line, title='Current AVG RSI Time Frame')
  128. fc1 = if rsi_avg_1 < rsi_avg
  129. color.new(color.red, 30)
  130. else
  131. color.new(color.green, 30)
  132. fill(rsi_avg_plot, rp1, color=fc1, transp=0)
  133.  
  134. fill_color = if rsi_avg > rsiCurrent and rsi_avg[1] - rsi_avg[0] > rsi_avg_step
  135. color.new(color.red, 50)
  136. else if rsi_avg < rsiCurrent and rsi_avg[0] - rsi_avg[1] > rsi_avg_step
  137. color.new(color.green, 50)
  138. fill(rsi_current_plot, rsi_avg_plot, color=fill_color, editable=true, title='RSI BAND', transp=50)
  139.  
  140. b1z = hline(70, color=color.new(color.green, 100), linestyle=hline.style_dotted, linewidth=1, title='Top Range')
  141. bz = hline(60, color=color.new(color.green, 100), linestyle=hline.style_dotted, linewidth=1, title='High Range')
  142. sz = hline(40, color=color.new(color.red, 100), linestyle=hline.style_dotted, linewidth=1, title='Low Range')
  143. s1z = hline(30, color=color.new(color.red, 100), linestyle=hline.style_dotted, linewidth=1, title='Bottom Range')
  144. mz = hline(50, color=color.black, linestyle=hline.style_dotted, linewidth=1, title='Mid Range')
  145. fill(b1z, bz, color=color.new(color.green, 80))
  146. fill(s1z, sz, color=color.new(color.red, 80))
  147.  
  148. buy_zone = if rsi_avg[0] - rsi_avg[1] > 1
  149. true
  150. else
  151. false
  152. plotshape(buy_zone, style=shape.triangleup, location=location.bottom, color=color.new(color.green, 0), size=size.tiny, title='Bulish Symbol')
  153.  
  154. sell_zone = if rsi_avg[2] - rsi_avg[1] > 1
  155. true
  156. else
  157. false
  158. plotshape(sell_zone, style=shape.triangledown, location=location.top, color=color.new(color.red, 0), size=size.tiny, title='Bearish Symbol')
  159.  
  160.  
  161. //end of this part
  162.  
  163. //@version=5
  164. //indicator(title="Money Flow Index", shorttitle="MFI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
  165. lengths = input.int(title="Length", defval=14, minval=1, maxval=2000)
  166. //src = input(hlc3)
  167. mf = ta.mfi(src, lengths)
  168. overbought=hline(80, title="Overbought", color=#787B86)
  169. oversold=hline(20, title="Oversold", color=#787B86)
  170. fill(overbought, oversold, color=color.rgb(126, 87, 194, 90), title="Background")
  171. mid = plot(50, color=color.black)
  172.  
  173. lens = 14
  174. upd = ta.rma(math.max(ta.change(close), 0), lens)
  175. downd = ta.rma(-math.min(ta.change(close), 0), lens)
  176. rsis = downd == 0 ? 100 : upd == 0 ? 0 : 100 - (100 / (1 + upd / downd))
  177. l1 = plot(mf, "MF", color=color.blue)
  178. l2 = plot(rsis, "RSI", color=color.lime)
  179.  
  180. var c = color.black
  181. if (mf < 50 and rsis < 50)
  182. c := color.rgb(255, 0, 0, 80)
  183. else if (mf >= 50 and rsis >= 50)
  184. c := color.rgb(0, 255, 0, 80)
  185. else
  186. c := color.rgb(0, 0, 0, 0)
  187.  
  188. fill(l1, mid, color = c)
  189. fill(l2, mid, color = c)
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
Advertisement
Add Comment
Please, Sign In to add comment