switch close > open => isBuyVolume := true close < open => isBuyVolume := false
if isBuyVolume posVol += volume else negVol -= volume
posVol + negVol
// Function to identify support and resistance boxes calcSupportResistance(src, lookbackPeriod) => // Volume Vol = upAndDownVolume() vol_hi = ta.highest(Vol / 2.5, vol_len) vol_lo = ta.lowest(Vol / 2.5, vol_len)
var float supportLevel = na var float supportLevel_1 = na var float resistanceLevel = na var float resistanceLevel_1 = na var box sup = na var box res = na var color res_color = na var color sup_color = na var float multi = na
var bool brekout_res = na var bool brekout_sup = na var bool res_holds = na var bool sup_holds = na
// Change Color of Support to red if it was break, change color of resistance to green if it was break if brekout_sup sup.set_bgcolor(color.new(color.red, 80)) sup.set_border_color(color.red) sup.set_border_style(line.style_dashed)
if sup_holds sup.set_bgcolor(sup_color) sup.set_border_color(color.green) sup.set_border_style(line.style_solid)
if brekout_res res.set_bgcolor(color.new(color.green, 80)) res.set_border_color(color.new(color.green, 0)) res.set_border_style(line.style_dashed)
if res_holds res.set_bgcolor(res_color) res.set_border_color(color.new(color.red, 0)) res.set_border_style(line.style_solid)
// Calculate support and resistance levels and their breakouts [supportLevel, resistanceLevel, brekout_res, res_holds, sup_holds, brekout_sup] = calcSupportResistance(close, lookbackPeriod)
// Check if Resistance becomes Support or Support Becomes Resistance var bool res_is_sup = na var bool sup_is_res = na
// Plot Res and Sup breakouts and holds plotchar(res_holds, "Resistance Holds", "◆", color = #e92929, size = size.tiny, location = location.abovebar, offset = -1) plotchar(sup_holds, "Support Holds", "◆", color = #20ca26, size = size.tiny, location = location.belowbar, offset = -1)
plotchar(brekout_res and res_is_sup[1], "Resistance as Support Holds", "◆", color = #20ca26, size = size.tiny, location = location.belowbar, offset = -1) plotchar(brekout_sup and sup_is_res[1], "Support as Resistance Holds", "◆", color = #e92929, size = size.tiny, location = location.abovebar, offset = -1)
// Break Out Labels if brekout_sup and not sup_is_res[1] label.new( bar_index[1], supportLevel[1], text = "Break Sup", style = label.style_label_down, color = #7e1e1e, textcolor = chart.fg_color, size = size.small )
if brekout_res and not res_is_sup[1] label.new( bar_index[1], resistanceLevel[1], text = "Break Res", style = label.style_label_up, color = #2b6d2d, textcolor = chart.fg_color, size = size.small )