// RSI custom (with & without scale)
//
// (https://www.prorealcode.com/topic/indicatore-rsi/#post-51250)
// (https://www.investopedia.com/terms/r/rsi.asp)
//
// p = 14 //periods
p = max(1,min(p,999)) //1 - 999
Ob = 70 //OverBought
Os = 100 - Ob //OverSold
Middle = 50 //mean line
//
r = 0
g = 0
b = 255
t = 255
//
Bullish = MAX(0, CLOSE - CLOSE[1])
Bearish = MAX(0, CLOSE[1] - CLOSE)
//
mmBullish = WILDERAVERAGE[p](Bullish)
mmBearish = WILDERAVERAGE[p](Bearish)
//
RS = mmBullish / mmBearish
IF ScaleEnabled THEN
myRSI = 100 - (100 / (1 + RS)) //scale
ELSE
MyRSI = RS //no scale
t = 0
Ob = MyRSI
Os = MyRSI
Middle = MyRSI
ENDIF
//
RETURN MyRSI AS "Rsi",Os coloured(r,g,b,t) AS "Os",Ob coloured(r,g,b,t) AS "Ob", Middle coloured(r,g,b,t) as "Mid"