Multi EMA - Saurabh
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © saurabh_gupta_

//@version=4
//Multi EMA 2



study(title="Multi EMA", shorttitle="Multi EMA", overlay=true)
src = close, 
len1 = input(20, minval=1, title="EMA 1")
len2 = input(50, minval=1, title="EMA 2")
len3 = input(200, minval=1, title="EMA 3")


ema1 = ema(src, len1)
ema2 = ema(src, len2)
ema3 = ema(src, len3)

//Color based on close price above or below
ema2Col=(close>ema2 ? color.lime :color.red)



//EMA Plots
plot(ema1, title="EMA 1",  linewidth=2, color=color.blue)
plot(ema2, title="EMA 2",  linewidth=3, color=ema2Col)
plot(ema3, title="EMA 3",  linewidth=2, color=color.purple)




//
toggleBreaks  = input(true, title = "Show Breaks" )
leftBars  = input(15, title = "Left Bars ")
rightBars  = input(15, title = "Right Bars")
volumeThresh  = input(20, title = "Volume Threshold")
//
highUsePivot = fixnan(pivothigh(leftBars, rightBars)[1])
lowUsePivot = fixnan(pivotlow(leftBars, rightBars)[1])
r1 = plot(highUsePivot, color=change(highUsePivot) ? na : #FF0000,  linewidth=3, offset=-(rightBars+1), title="Resistance")
s1 = plot(lowUsePivot, color=change(lowUsePivot) ? na : #233dee,  linewidth=3, offset=-(rightBars+1), title="Support")

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


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

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


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


// //MA
// sma =ema(close,50)
// multp = input(type=input.float, defval=2)
// len = input(type=input.integer, defval=7)
// [superTrend, dir] = supertrend(multp, len)
// col1 = (dir==1?color.red:color.lime)
// // longStopPlot = plot(dir == -1 ? superTrend : na, style=plot.style_linebr, color=color.gray, linewidth=1)
// // shortStopPlot = plot(dir ==  1 ? superTrend : na, style=plot.style_linebr, color=color.gray, linewidth=1)
// col2=(close<sma ? (close>superTrend? color.blue :color.red) : (close<superTrend ? color.purple :color.lime))
// ma=plot(sma,color=col2,linewidth=2)
// // fill(ma, longStopPlot, title="Long State Filling", color=col2, transp=70)
// // fill(ma, shortStopPlot, title="Short State Filling", color=col2,transp=70)



//Previous and current VWap
//Previous Day's Closing Vwap (Pvwap)
// newday(res) =>
//     t = time(res)
//     change(t) != 0 ? 1 : 0
// new_day = newday("D")
// // prev_vwap = valuewhen(new_day, int(vwap[1]), 0)
// show = timeframe.isintraday 
// var line vwapLine = na
// if show 
//     // if prev_vwap[1] != prev_vwap
//     //     line.set_x2(vwapLine, bar_index)
//     //     line.set_extend(vwapLine, extend.none)
//         // vwapLine := line.new(bar_index, prev_vwap, bar_index, prev_vwap, width=1, style=line.style_dashed,color=color.black)
//         // label.new(bar_index, prev_vwap, "\n" + tostring(prev_vwap, "#.##"), style=label.style_none, size=size.large, textcolor=color.black)
    
//     if not na(vwapLine) and line.get_x2(vwapLine) != bar_index
//         line.set_x2(vwapLine, bar_index)

// // col = close>prev_vwap?(close>vwap?color.lime:color.blue):(close<vwap?color.red:color.purple)

hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="VWAP Settings")

// if not (hideonDWM and timeframe.isdwm)
plot(vwap,linewidth=3, color=color.orange)
// barcolor(col)