xmd79

RSI Supply & Demand Zones

Oct 6th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 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. // © mikeright25
  3.  
  4. //@version=5
  5. indicator("RSI Supply & Demand Zones", overlay=true)
  6.  
  7. //inputs
  8. src = close
  9. len = input(10, title='RSI Length', group="RSI Supply/Demand Zone") //def 14 or 12 or 10
  10. thresh = input.int(43, minval=1, title='RSI Threshold') //eg. 100 - 30 = 70..... //75 or 42 or 43
  11. count = input(3, title='RSI Confirmation Bars') //4 or 2 or 3
  12. rsion = input(defval=true, title='RSI S/D')
  13.  
  14. //color
  15. colorhigh = input(defval=color.new(color.fuchsia, 65), title='RSI Supply Color')
  16. colorlow = input(defval=color.new(color.blue, 65), title='RSI Demand Color')
  17.  
  18. ///get rsi
  19. up = ta.rma(math.max(ta.change(src), 0), len)
  20. down = ta.rma(-math.min(ta.change(src), 0), len)
  21. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
  22.  
  23.  
  24. upper_threshold = 100 - thresh
  25. lower_threshold = 0 + thresh
  26.  
  27. rsu = 0
  28. rsd = 0
  29. rsx = 0
  30. incrementer_up = rsi > upper_threshold ? 1 : 0
  31. incrementer_down = rsi < lower_threshold ? 1 : 0
  32. incrementer_both = rsi > upper_threshold or rsi < lower_threshold ? 1 : 0
  33.  
  34. if incrementer_both
  35. rsx := nz(rsx[1], 0) + incrementer_both
  36. rsx
  37. else
  38. rsx := 0
  39. rsx
  40.  
  41. rxH = if rsx >= count
  42. x = high
  43. x
  44. rxL = if rsx >= count
  45. y = low
  46. y
  47.  
  48. rH = fixnan(rxH)
  49. rL = fixnan(rxL)
  50.  
  51.  
  52. if incrementer_up
  53. rsu := nz(rsu[1], 0) + incrementer_up
  54. rsu
  55. else
  56. rsu := 0
  57. rsu
  58.  
  59. rssH = if rsu >= count
  60. x = high
  61. x
  62.  
  63. rssL = if rsu >= count
  64. y = low
  65. y
  66.  
  67. if incrementer_down
  68. rsd := nz(rsd[1], 0) + incrementer_down
  69. rsd
  70. else
  71. rsd := 0
  72. rsd
  73.  
  74. rsrH = if rsd >= count
  75. x = high
  76. x
  77.  
  78. rsrL = if rsd >= count
  79. y = low
  80. y
  81.  
  82. rsh = fixnan(rssH)
  83. rsl = fixnan(rssL)
  84. rdh = fixnan(rsrH)
  85. rdl = fixnan(rsrL)
  86.  
  87. ///Plot
  88.  
  89. p5 = plot(rsion and rsh ? rsh : na, style=plot.style_circles, title='RSI Supply High', color=colorhigh)
  90. p6 = plot(rsion and rsl ? rsl : na, style=plot.style_circles, title='RSI Supply Low', color=colorhigh)
  91. p7 = plot(rsion and rdh? rdh : na, style=plot.style_circles, title='RSI Demand High', color=colorlow )
  92. p8 = plot(rsion and rdl? rdl : na, style=plot.style_circles, title='RSI Demand Low', color=colorlow)
  93.  
  94. fill(p5, p6, color=color.new(colorhigh, 90), title='RSI Supply Zone')
  95. fill(p7, p8, color=color.new(colorlow, 90), title='RSI Demand Zone')
  96.  
  97.  
Advertisement
Add Comment
Please, Sign In to add comment