Percent of U.S. Stocks Above VWAP
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BigGuavaTrading
//@version=5
indicator("Percent of Stocks Above VWAP", "Percent of Stocks Above VWAP", false)

//Set overbought and oversold
ob = input(60, "Overbought Level")
os = input(40, "Oversold Level")

//Plot data
PCTABOVEVWAP = request.security('PCTABOVEVWAP.US', "", close) 
c = PCTABOVEVWAP > PCTABOVEVWAP[1] ? color.green : color.red  //sets line color
plot(PCTABOVEVWAP, 'Percent above VWAP', c, 3, plot.style_line)  //plots line

cema = ta.ema(PCTABOVEVWAP, input(5, "EMA of Line")) //establish EMA for smoothing
b = cema > cema[1] ? color.purple : color.yellow //sets EMA color
plot(cema, "EMA of Line", b, 3, plot.style_line) //plots EMA

maxBand = hline(100, "Max Level", linestyle=hline.style_dotted)
hline(0, "Zero Level", linestyle=hline.style_dotted)
minBand = hline(0, "Min Level", linestyle=hline.style_dotted)

obLine = hline(ob, "Overbought Level", linestyle=hline.style_dotted)
osLine = hline(os, "Oversold Level", linestyle=hline.style_dotted)
hline(50, "Zero line", color.black, linestyle=hline.style_dotted)  //sets 50% line

fill(maxBand, obLine, PCTABOVEVWAP > ob ? color.rgb(76, 175, 79, 80) : na)
fill(minBand, osLine, PCTABOVEVWAP < os ? color.rgb(255, 82, 82, 80) : na)
plotshape(ta.crossover(PCTABOVEVWAP, 50), "VWAP bull cross", shape.triangleup, location.bottom, color.green, size=size.small)
plotshape(ta.crossunder(PCTABOVEVWAP, 50), "VWAP bear cross", shape.triangledown, location.top, color.red, size=size.small)
