Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © mikeright25
- //@version=5
- indicator("RSI Supply & Demand Zones", overlay=true)
- //inputs
- src = close
- len = input(10, title='RSI Length', group="RSI Supply/Demand Zone") //def 14 or 12 or 10
- thresh = input.int(43, minval=1, title='RSI Threshold') //eg. 100 - 30 = 70..... //75 or 42 or 43
- count = input(3, title='RSI Confirmation Bars') //4 or 2 or 3
- rsion = input(defval=true, title='RSI S/D')
- //color
- colorhigh = input(defval=color.new(color.fuchsia, 65), title='RSI Supply Color')
- colorlow = input(defval=color.new(color.blue, 65), title='RSI Demand Color')
- ///get rsi
- up = ta.rma(math.max(ta.change(src), 0), len)
- down = ta.rma(-math.min(ta.change(src), 0), len)
- rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
- upper_threshold = 100 - thresh
- lower_threshold = 0 + thresh
- rsu = 0
- rsd = 0
- rsx = 0
- incrementer_up = rsi > upper_threshold ? 1 : 0
- incrementer_down = rsi < lower_threshold ? 1 : 0
- incrementer_both = rsi > upper_threshold or rsi < lower_threshold ? 1 : 0
- if incrementer_both
- rsx := nz(rsx[1], 0) + incrementer_both
- rsx
- else
- rsx := 0
- rsx
- rxH = if rsx >= count
- x = high
- x
- rxL = if rsx >= count
- y = low
- y
- rH = fixnan(rxH)
- rL = fixnan(rxL)
- if incrementer_up
- rsu := nz(rsu[1], 0) + incrementer_up
- rsu
- else
- rsu := 0
- rsu
- rssH = if rsu >= count
- x = high
- x
- rssL = if rsu >= count
- y = low
- y
- if incrementer_down
- rsd := nz(rsd[1], 0) + incrementer_down
- rsd
- else
- rsd := 0
- rsd
- rsrH = if rsd >= count
- x = high
- x
- rsrL = if rsd >= count
- y = low
- y
- rsh = fixnan(rssH)
- rsl = fixnan(rssL)
- rdh = fixnan(rsrH)
- rdl = fixnan(rsrL)
- ///Plot
- p5 = plot(rsion and rsh ? rsh : na, style=plot.style_circles, title='RSI Supply High', color=colorhigh)
- p6 = plot(rsion and rsl ? rsl : na, style=plot.style_circles, title='RSI Supply Low', color=colorhigh)
- p7 = plot(rsion and rdh? rdh : na, style=plot.style_circles, title='RSI Demand High', color=colorlow )
- p8 = plot(rsion and rdl? rdl : na, style=plot.style_circles, title='RSI Demand Low', color=colorlow)
- fill(p5, p6, color=color.new(colorhigh, 90), title='RSI Supply Zone')
- fill(p7, p8, color=color.new(colorlow, 90), title='RSI Demand Zone')
Advertisement
Add Comment
Please, Sign In to add comment