S/R and Reversal Bars
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pratik_4Clover
//@version=5
indicator("S/R and Reversal Bars", shorttitle="RB",overlay=true, max_bars_back=500)

ShowSR=input(true, title="Show S/R levels")
cci = ta.cci(close, 20)

ccih = cci >= 200
ccil = cci <= -200
CcColor = ccih ? color.yellow : ccil ? color.white : na
plotshape(ccih, style=shape.triangleup, location=location.abovebar, color=CcColor, title='CCI+', editable=false, size=size.auto)
plotshape(ccil, style=shape.triangledown, location=location.belowbar, color=CcColor, title='CCI-', editable=false, size=size.auto)

ccihcu = ta.crossunder(cci, 180)
ccilcu = ta.crossover(cci, -180)

plotshape(ccihcu, style=shape.circle, location=location.abovebar, color=color.new(#ff1100, 0), title='CCI+180', editable=false, size=size.auto)
plotshape(ccilcu, style=shape.circle, location=location.belowbar, color=color.new(color.lime, 0), title='CCI-180', editable=false, size=size.auto)

// Add high and low candle zones
var highZone = high
var lowZone = low
var flag = false
for i = 0 to bar_index
    if ccilcu[i]
        lowZone := low[i]
        flag := true
        break
    else if ccihcu[i]
        highZone := high[i]
        flag := true
        break
    if flag
        break

plot(ShowSR ? highZone :na, title="High Zone", color=color.red, style=plot.style_cross, linewidth=2, editable=false, show_last=150)
plot(ShowSR ? lowZone :na , title="Low Zone", color=color.lime, style=plot.style_cross, linewidth=2, editable=false, show_last=150)

ccihcu2 = ta.crossover(cci, 70)
ccilcu2 = ta.crossunder(cci, -70)

var highZone2 = high
var lowZone2 = low
var flag2 = false
for i = 0 to bar_index
    if ccilcu2[i]
        lowZone2 := low[i]
        flag2 := true
        break
    else if ccihcu2[i]
        highZone2 := high[i]
        flag2 := true
        break

plot(ShowSR ? highZone2 :na, title="High Zone", color=color.orange, style=plot.style_circles, linewidth=1, editable=false, show_last=150)
plot(ShowSR ? lowZone2 :na, title="Low Zone", color=color.green, style=plot.style_circles, linewidth=1, editable=false, show_last=150)

//..zero

zerocci=ta.crossunder(ta.cci(close, 20), -0)

var cent = hl2
var flag3 = false

for i = 0 to bar_index
    if zerocci[i]
        cent := low[i]
        flag3 := true
        break

plot(ShowSR ? cent :na, title="Central", color=color.new(color.yellow,0), style=plot.style_circles, linewidth=1, editable=false, show_last=150)
