 Sup/Res Levels [QuantVue]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © QuantVue

//@version=5
indicator(title=' Support and Resistance Levels [QuantVue]', shorttitle=' Support and Resistance Levels [QuantVue]', overlay=true, max_bars_back=1000)
//
toggleBreaks = input(true, title='Breaks')
leftBars = input(20, title='Left Bars ')
rightBars = input(20, title='Right Bars')
volumeThresh = input(25, title='Volume Thres')
//
highUsePivot = fixnan(ta.pivothigh(leftBars, rightBars)[1])
lowUsePivot = fixnan(ta.pivotlow(leftBars, rightBars)[1])
r1 = plot(highUsePivot, color=ta.change(highUsePivot) ? na : #e08686, linewidth=2, offset=-(rightBars + 1), title='Resistance')
s1 = plot(lowUsePivot, color=ta.change(lowUsePivot) ? na : #7edb97, linewidth=2, offset=-(rightBars + 1), title='Support')

//Volume %
short = ta.ema(volume, 5)
long = ta.ema(volume, 10)
osc = 100 * (short - long) / long


//For breaks with volume
plotshape(toggleBreaks and ta.crossunder(close, lowUsePivot) and not(open - close < high - open) and osc > volumeThresh, title='Break', text='B', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(toggleBreaks and ta.crossover(close, highUsePivot) and not(open - low > close - open) and osc > volumeThresh, title='Break', text='B', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)

//For bull / bear wicks
plotshape(toggleBreaks and ta.crossover(close, highUsePivot) and open - low > close - open, title='Break', text='Bull Wick', style=shape.labelup, location=location.belowbar, color=color.rgb(137, 178, 139), textcolor=color.new(color.white, 0), size=size.tiny, transp=0)
plotshape(toggleBreaks and ta.crossunder(close, lowUsePivot) and open - close < high - open, title='Break', text='Bear Wick', style=shape.labeldown, location=location.abovebar, color=color.rgb(236, 131, 131), textcolor=color.new(color.white, 0), size=size.tiny, transp=0)


alertcondition(ta.crossunder(close, lowUsePivot) and osc > volumeThresh, title='Support Broken', message='Support Broken')
alertcondition(ta.crossover(close, highUsePivot) and osc > volumeThresh, title='Resistance Broken', message='Resistance Broken')

