//Author - DieciTrader
//Original Author - Rajandran R (thanks for this great script!)
//@version=2
strategy("ST_Bounce", overlay=true)//, initial_capital=10000, currency='INR')
//study("ST_Bounce", overlay=true)
Factor=input(3, minval=1,maxval = 100)
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 ? green : red
plot(Tsl, color = linecolor , style = line , linewidth = 2,title = "SuperTrend")
//plotshape(cross(high,Tsl) and close>Tsl , "Up Arrow", shape.triangleup,location.belowbar,green,0,0)
//plotshape(cross(Tsl,low) and close<Tsl , "Down Arrow", shape.triangledown , location.abovebar, red,0,0)
//plotarrow(Trend == 1 and Trend[1] == -1 ? Trend : na, title="Up Entry Arrow", colorup=lime, maxheight=60, minheight=50, transp=0)
//plotarrow(Trend == -1 and Trend[1] == 1 ? Trend : na, title="Down Entry Arrow", colordown=red, maxheight=60, minheight=50, transp=0)
plotarrow(Trend == 1 and close > Tsl and low < Tsl ? Trend : na, title="Up Entry Arrow", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(Trend == -1 and close < Tsl and high > Tsl ? Trend : na, title="Down Entry Arrow", colordown=red, maxheight=60, minheight=50, transp=0)
//golong = Trend == 1 and Trend[1] == -1
//alertcondition(golong, title='Long', message='SuperTrend V.1 Alert Long')
//goshort = Trend == -1 and Trend[1] == 1
//alertcondition(goshort, title='Short', message='SuperTrend V.1 Alert Short')
longC = (Trend == 1 and close > Tsl and low < Tsl)
shortC = (Trend == -1 and close < Tsl and high > Tsl)
strategy.entry("longCall", strategy.long, when = longC)
strategy.entry("shortCall", strategy.short, when = shortC)
longexit = (Trend == -1)
shortexit = (Trend == 1)
if(longexit)
strategy.close("longCall")
if(shortexit)
strategy.close("shortCall")
//strategy.exit("longCall", "long", when = longexit)
//strategy.exit("shortCall", "short", when = shortexit)