//------------------------------------------//
//PRC_SuperTrend
//www.prorealcode.com
//Sharing ProRealTime knowledge
//------------------------------------------//
//-----Inputs-------------------------------//
//------------------------------------------//
periods = 10 //ATR period
multiplier = 3 //ATR multiplier
//------------------------------------------//
//----SuperTrend Calculation----------------//
//------------------------------------------//
atr = averagetruerange[periods](close)
up = high - multiplier*atr
up1 = up[1]
if close[1] > up1 then
up = max(up,up1)
else
up = up
endif
dn = low + multiplier*atr
dn1 = dn[1]
if close[1] < dn1 then
dn = min(dn,dn1)
else
dn = dn
endif
once trend = 1
if trend = -1 and close > dn1 then
trend = 1
elsif trend = 1 and close < up1 then
trend = -1
else
trend = trend
endif
//------------------------------------------//
//----Buy and Sell Signals------------------//
//------------------------------------------//
buysignal = trend=1 and trend[1]=-1
sellsignal = trend=-1 and trend[1]=1
screener[buysignal or sellsignal](buysignal as "Buy",sellsignal as "Sell")