//------------------------------------------------------------------------//
//PRC_RSI Fukuiz Trend
//version = 0
//30.05.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//------------------------------------------------------------------------//
//-----Inputs-------------------------------------------------------------//
//-----RSI
len=25
len2=100
src=close
//-----Pivots
lbR=5//lookback Right
lbL=lbR//lookback Left
//-----Divergences
rangeUpper=60
rangeLower=5
showdiv=1
//------------------------------------------------------------------------//
//------------------------------------------------------------------------//
srcUp=max(close-close[1],0)
srcDw=-min(close-close[1],0)
alpha=1/len
if barindex=len then
up=average[len](srcup)
dw=average[len](srcdw)
else
up=alpha*srcup+(1-alpha)*up[1]
dw=alpha*srcdw+(1-alpha)*dw[1]
endif
alpha2=1/len2
if barindex=len2 then
up2=average[len2](srcup)
dw2=average[len2](srcdw)
else
up2=alpha2*srcup+(1-alpha2)*up2[1]
dw2=alpha2*srcdw+(1-alpha2)*dw2[1]
endif
if dw=0 then
myrsi=100
elsif up=0 then
myrsi=0
else
myrsi=100-100/(1+up/dw)
endif
if dw2=0 then
myrsi2=100
elsif up2=0 then
myrsi2=0
else
myrsi2=100-100/(1+up2/dw2)
endif
//------------------------------------------------------------------------//
//------------------------------------------------------------------------//
bullish=myrsi>myrsi2
bearish=myrsi<myrsi2
//------------------------------------------------------------------------//
//-----Pivots High-Low ---------------------------------------------------//
osc=rsi[len](src)
src1=osc
//------------------------------------------------------------------------//
//-----pivots low
if src1 > src1[lbR] and lowest[lbR](src1) > src1[lbR] and src1[lbR] < lowest[lbL](src1)[lbR+1] then
$pl[z+1]=src1[lbR]
$plx[z+1]=barindex[lbR]
$priceL[z+1]=low[lbR]
z=z+1
endif
//-----pivots high
if src1 < src1[lbR] and highest[lbR](src1)<src1[lbR] and src1[lbR]>highest[lbL](src1)[lbR+1] then
$ph[t+1]=src1[lbR]
$phx[t+1]=barindex[lbR]
$priceH[t+1]=high[lbR]
t=t+1
endif
//-----New Pivot found
plfound=z<>z[1]
phfound=t<>t[1]
//------------------------------------------------------------------------//
//-----Divergences--------------------------------------------------------//
//-----Bullish Divergences
oscHL = $pl[z]>$pl[max(0,z-1)] and (barindex-$plx[max(0,z-1)])<=rangeUpper and (barindex-$plx[max(0,z-1)])>=rangeLower
priceLL = $priceL[z]<$priceL[max(0,z-1)]
bullcond = plfound and oscHL and priceLL
if bullcond and showdiv then
drawarrowup(barindex[lbR],osc[lbR]-3)coloured("green")
drawsegment($plx[max(0,z-1)],$pl[max(0,z-1)],$plx[z],$pl[z])coloured("green")
endif
//-----Bearish Divergences
oscLH = $ph[t]<$ph[max(0,t-1)] and (barindex-$phx[max(0,t-1)])<=rangeUpper and (barindex-$phx[max(0,t-1)])>=rangeLower
priceHH = $priceH[t]>$priceH[max(0,t-1)]
bearCond = phfound and oscLH and priceHH
if bearCond and showdiv then
drawarrowdown(barindex[lbR],osc[lbR]+3)coloured("red")
drawsegment($phx[max(0,t-1)],$ph[max(0,t-1)],$phx[t],$ph[t])coloured("red")
endif
//------------------------------------------------------------------------//
//-----Plot bands---------------------------------------------------------//
bandDw=30
bandMd=50
bandUp=70
//-----Colours------------------------------------------------------------//
if bullish then
r=102
g=51
b=255
rr=51
gg=204
bb=255
elsif bearish then
r=255
g=51
b=51
rr=255
gg=51
bb=102
endif
colorbetween(myrsi,myrsi2,r,g,b,50)
//------------------------------------------------------------------------//
return myrsi as "RSI Short"coloured(r,g,b)style(line,2),myrsi2 as "RSI Long"coloured(rr,gg,bb)style(line,2),bandDw as "Lower Band"coloured("orange")style(dottedline),bandUp as"Upper Band"coloured("orange")style(dottedline),bandMd as "Middle Band"coloured("orange")style(dottedline)