//--------------------------------------------------------------------//
//PRC_RSI Supertrend
//version = 0
//03.06.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//--------------------------------------------------------------------//
//-----Inputs---------------------------------------------------------//
relativeStrengthIndexLength=14
smoothingLength=21
rsiInputSource = customclose
isSmoothed=0
movingAverageLength=14
movingAverageType=7 //
showMovingAverage=1
trendFactor=0.8
averageTrueRangeLength=10
obline=70
osline=30
midline=50
transparency=80
//--------------------------------------------------------------------//
//-----RSI Calculation------------------------------------------------//
if isSmoothed then
auxrsi=rsi[relativeStrengthIndexLength](rsiInputSource)
myrsi=hullaverage[smoothingLength](auxrsi)
else
myrsi=rsi[relativeStrengthIndexLength](rsiInputSource)
endif
rsiMovingAverage=average[movingAverageLength,movingAverageType](myrsi)
//--------------------------------------------------------------------//
//-----Calculating Supertrend based on RSI values---------------------//
pricesource=myrsi
highestHigh=highest[averageTrueRangeLength](pricesource)
lowestlow=lowest[averageTrueRangeLength](pricesource)
if barindex <= averageTrueRangeLength then
truerange=highestHigh-lowestlow
else
truerange=max(highestHigh-lowestlow,max(abs(highestHigh-pricesource[1]),abs(lowestlow-pricesource[1])))
endif
alpha = 1/averageTrueRangeLength
if barindex <= 4*averageTrueRangeLength then
atr = average[averageTrueRangeLength](truerange)
else
atr = alpha*truerange + (1-alpha)*atr[1]
endif
up = pricesource - trendFactor*atr
up1 = up[1]
if pricesource[1] > up1 then
up = max(up,up1)
else
up = up
endif
dn = pricesource + trendFactor*atr
dn1 = dn[1]
if pricesource[1] < dn1 then
dn = min(dn,dn1)
else
dn = dn
endif
once trend = 1
if trend = -1 and pricesource > dn1 then
trend = 1
elsif trend = 1 and pricesource < up1 then
trend = -1
else
trend = trend
endif
if trend = 1 then
mysupertrend = up
else
mysupertrend = dn
endif
//--------------------------------------------------------------------//
if trend=1 then
r=0
g=255
b=187
else
r=255
g=17
b=0
endif
//--------------------------------------------------------------------//
colorbetween(mysupertrend,pricesource,r,g,b,transparency)
//--------------------------------------------------------------------//
if mysupertrend crosses over pricesource and mysupertrend>Obline then
drawtext("▼",barindex,mysupertrend+2)coloured("red")
elsif mysupertrend crosses under pricesource and mysupertrend<osline then
drawtext("▲",barindex,mysupertrend-2)coloured("green")
endif
//--------------------------------------------------------------------//
return pricesource,mysupertrend coloured(r,g,b),rsiMovingAverage coloured("grey")style(line,2),obline as "Overbought Line" coloured("grey")style(dottedline),osline as "Overbought Line" coloured("grey")style(dottedline),midline as "Middle Line" coloured("grey")style(dottedline2)