//@version=2
//Original author: Rajandran R from
www.marketcalls.in
study("Supertrend Alerts 1.1", overlay = true)
cand_col = input(title="Color Candles", type=bool, defval=true)
show_line = input(title="Show Supertrend Line", type=bool, defval=true)
Factor = input(3, type=float)
PD = input(7, minval = 1, maxval = 100)
Up=hl2-(Factor*atr(PD))
Dn=hl2+(Factor*atr(PD))
TrendUp = close[1] > TrendUp[1] ? max(Up, TrendUp[1]) : Up
TrendDown = close[1] < TrendDown[1] ? min(Dn, TrendDown[1]) : Dn
Trend = close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1], 1)
TSL = Trend == 1 ? TrendUp : TrendDown
linecolor = Trend == 1 ? color(green, 0) : color(red, 0)
barcolor((cand_col and Trend == 1) ? color(green, 0) : na)
barcolor((cand_col and Trend == -1) ? color(red, 0) : na)
plot(show_line ? TSL : na, color = linecolor , style = line , linewidth = 2, title = "SuperTrend Line", transp=65)
newup = cross(close,TSL) and close>TSL
newdn = cross(TSL,close) and close<TSL
plotshape(newup, "Long", shape.triangleup, location.belowbar, color(green, 0), size=size.normal)
plotshape(newdn, "Short", shape.triangledown , location.abovebar, color(red, 0), size=size.normal)
alertcondition(newup, title='Supertrend Long', message='Supertrend: Long ')
alertcondition(newdn, title='Supertrend Short', message='Supertrend: Short ')
alertcondition(newup or newdn, title='Supertrend Signal', message='Supertrend: Long or Short ')