// --- settings
inpPeriod = 9
once alpha=1.0/max(inpPeriod,1)
once FLTMIN=ticksize
if barindex>inpPeriod then
diff = high - close[1]
ChangeHigh = ChangeHigh[1] + alpha*(diff - ChangeHigh[1])
ChangaHigh = ChangaHigh[1] + alpha*(abs(diff) - ChangaHigh[1])
RSIHigh = 50.0*(ChangeHigh/max(ChangaHigh,FLTMIN)+1)
endif
//-----Inputs----------------------------------------//
length = 9 //Period of evaluation
smooth = 3 //Period of smoothing
src = customclose
Mode = 1 //RSI = 1 / Stochastic = 2 / ADX = 3
Matype = 2 //Moving average Type - WMA by default
//---------------------------------------------------//
//-----Bull and Bear Trends calculation-------------//
if mode = 2 then //Stochastic
Bulls = src - lowest[length](src)
Bears = highest[Length](src)-src
elsif mode = 3 then //ADX
Bulls = 0.5*(abs(high-high[1])+(high-high[1]))
Bears = 0.5*(abs(low[1]-low)+(low[1]-low))
else //RSI
Bulls = 0.5*(abs(src-src[1])+(src-src[1]))
Bears = 0.5*(abs(src-src[1])-(src-src[1]))
endif
avgbulls = average[length,maType](Bulls)
avgbears = average[length,maType](Bears)
SmthBulls = average[Smooth,maType](avgbulls)
SmthBears = average[Smooth,maType](avgbears)
//inputs
TS = 20 //% Trailing stop
//TSswitch = 1 // Display Stoploss
//BGswitch = 1 // Display BG color
//REswtich = 1 // Display Re-entry
////
wma62 = average[62,2](close)
wma4 = average[4,2](close)
tsPercent = TS/100 //Trailing stop
enterlong = wma62>wma62[1] and close>wma4 and close[1]>wma4[1] and close>close[1]
entershort = wma62<wma62[1] and close<wma4 and close[1]<wma4[1] and close<close[1]
once trailTop = close
if close>trailtop[1] or close<trailtop[1]*(1-tspercent) or entershort then
trailTop = close
else
trailTop = trailTop[1]
endif
once trailBot = close
if close<trailBot[1] or close>trailBot[1]*(1+tspercent) or enterlong then
trailBot = close
else
trailBot = trailBot[1]
endif
exitlong = trailTop < trailTop[1]
exitsh = trailBot > trailBot[1]
if enterlong then
inlong = 1
elsif entershort or exitlong then
inlong = 0
else
inlong = inlong[1]
endif
if entershort then
inshort = 1
elsif enterlong or exitsh then
inshort = 0
else
inshort = inshort[1]
endif
SCREENER[RSIHigh>50 and SmthBulls>SmthBears and (enterlong and not inlong[1])](close as "close")