//--------------------------------------------------------------//
//----Inputs----------------------------------------------------//
rsisource=customclose
rsiLength=7
rsioverbought=70
rsioversold=30
//--------------------------------------------------------------//
//-----RSI value------------------------------------------------//
rsivalue=rsi[rsilength](rsiSource)
//-----Current State--------------------------------------------//
isOverbought = rsiValue >= rsiOverbought
isOversold = rsiValue <= rsioversold
//--------------------------------------------------------------//
//-----High and low channel-------------------------------------//
//---Low: calculated when is not overbought
if isOverbought then
notob=0
else
notob=notob+1
pl=lowest[notob](low)
plx=barindex-barssince(pl=low)
endif
//---High: calculated when is not oversold
if isOversold then
notos=0
else
notos=notos+1
ph=highest[notos](high)
phx=barindex - barssince(ph=high)
endif
//--------------------------------------------------------------//
//-----Pivot Points (High&Low)----------------------------------//
//---Check after exit oversold state
if isoversold[1] and not isoversold then
prevlastosx=lastosx//keep the previous pivot barindex
lastosx=plx//set the new pivot barindex
//---Draw only if is the last high
if lastosx>lastobx and prevlastosx < lastobx then
lasty1=y1
//x1=phx[1]
y1=ph[1]
if lasty1 > y1 then
setup=-1
//drawtext("LH",x1,y1+0.5*tr)coloured("red")
else
setup=1
//drawtext("HH",x1,y1+0.5*tr)coloured("red")
endif
endif
endif
//---Check after exit overbought state
if isOverbought[1] and not isOverbought then
prevlastobx=lastobx//keep the previous pivot barindex
lastobx=phx//set the new pivot barindex
//---Draw only if is the last low
if lastobx>lastosx and prevlastobx < lastosx then
lasty2=y2
//x2=plx[1]
y2=pl[1]
if lasty2 > y2 then
setup=-2
//drawtext("LL",x2,y2-0.5*tr)coloured("green")
else
setup=2
//drawtext("HL",x2,y2-0.5*tr)coloured("green")
endif
endif
endif
screener[setup=-2](setup)