Bar Retracement 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © grnghost

//@version=5
indicator("Retracement", "Bar RR", overlay = false, precision = 1)

var bw = high - low
var ret = open- close

bw_av = ta.sma(bw,4)
max_bw = ta.highest(bw,5)
mom = ta.sma(ta.mom(hl2,2),4)

if close[1] > open[1]
    bw := close[1] - low[1]
    ret := (low - open) / bw * 100
if close[1] < open[1] 
    bw :=  high[1] - close[1]
    ret := (open - high)/ bw * 100
ret := ret < -100 ? -100 : ret 
ret_red = close < open and close[1] > open[1]
ret_grn = close > open and close[1] < open[1]

ret_low = ret < -38.2 and ret > -61.7
ret_mid = ret < -61.8 and ret > -78.6 


ret_col = ret < -78.7 and ret_red ? color.new(color.red, 20) :  ret < -78.6 and ret_grn ? color.new(color.green,20) : ret_low ? color.new(color.yellow,20) : ret_mid ? color.new(color.orange,20) : color.new(color.silver,10)

plot(ret, color = ret_col, style = plot.style_histogram, linewidth = 2) //color.silver
plot(0, color = color.gray, display = display.pane) //color.new(color.gray, 20)
p1 = plot(-38.2, color = na, display = display.pane) // color.new(color.yellow,50))
p2 = plot(-61.8, color = color.new(color.orange,100), display = display.pane) //color.new(color.orange,50))
p3 = plot(-78.6, color = color.new(color.red,100), display = display.pane)
p4 = plot(-100, color =  color.new(color.red,100), display = display.pane)

fill(p1, p2, color.new(color.yellow,80))
fill(p2, p3, color.new(color.orange,80))
fill(p3, p4, color.new(color.red,80))

warn = ta.crossover(ret, -78.6)

alertcondition(warn, "Large Retracement", "Prepare to exit.")