//PRC_Twing Range Filter | screener
// --- settings
per1 = 27 //"Fast period"
mult1 = 1.6 //"Fast range"
per2 = 55 //"Slow period"
mult2 = 2 //"Slow range"
// --- end of settings
source = customclose
once wper1 = per1 * 2 - 1
avrng1 = average[per1,1](abs(source - source[1]))
smrng1 = average[wper1,1](avrng1) * mult1
once wper2 = per2 * 2 - 1
avrng2 = average[per2,1](abs(source - source[1]))
smrng2 = average[wper2,1](avrng2) * mult2
smrng = (smrng1 + smrng2) / 2
r = smrng
if source>rngfilt[1] then
if (source-r)<rngfilt[1] then
rngfilt=rngfilt[1]
else
rngfilt=source-r
endif
elsif (source+r)>rngfilt[1] then
rngfilt=rngfilt[1]
else
rngfilt=source+r
endif
if rngfilt > rngfilt[1] then
upward=upward+1
downward=0
endif
if rngfilt < rngfilt[1] then
upward=0
downward=downward+1
endif
longCond = (source > rngfilt and source > source[1] and upward > 0) or (source > rngfilt and source < source[1] and upward > 0)
shortCond = (source < rngfilt and source < source[1] and downward > 0) or (source < rngfilt and source > source[1] and downward > 0)
if longcond then
colorr=0
//colorg=255
elsif shortcond then
colorr=255
//colorg=0
endif
signal=0
if colorr=0 and colorr[1]=255 then
signal=1
//drawarrowup(barindex,min(low,rngfilt)-averagetruerange[14]/2) coloured("green")
endif
if colorr=255 and colorr[1]=0 then
signal=-1
//drawarrowdown(barindex,max(high,rngfilt)+averagetruerange[14]/2) coloured("crimson")
endif
screener[signal<>0] (signal as "signals")