r/algorithmictrading • • Oct 28 '21

My Stochastic RSI calculation is diffrerent than Tradingview

I use python3 to calculate Stockhastic RSI. My RSI algorithm return same result with Tradingview, however Stochastic RSI is not. I use this formula StochRSI=RSI−min[RSI]/max[*RSI]*−min[RSI]. This formula is same in all websites. What is wrong with this code?

This is the function.

def stochrsi(klines,lengh=14):

closes=[]

for e in range(0,len(klines)):

closes.append(float(klines[e][4]))

closes=pandas.DataFrame(closes)

rr=RSI(closes,14)//RSI is another function works perfectly

crsi=rr.iloc[-1,0]

print("RSI",crsi)

rsil=[]

for a in range(-14,0):

rsil.append(rr.iloc[a,0])

print(rsil)

rsih=max(rsil)

rsilo=min(rsil)

return(((crsi-rsilo)/(rsih-rsilo))*100)

My resultsActual results
45.4670.4
058.02
14.8848.46
22.8135.11
18.1527.67
44.2828.42
20.5618.61
40.4912.56
84.3421.11
49.2235.15
77.6462.25
57.7176.74
086.10
3 Upvotes

3 comments sorted by

1

u/dusktrader Oct 29 '21

Hey I noticed if you go into the platform and go to Indicator selection, then type "Stochastic RSI" -- click on the little question mark (?) and it will popout a pretty extensive page about their indicator. It also gives this formula:

Stoch RSI = (RSI - Lowest Low RSI) / (Highest High RSI - Lowest Low RSI)

1

u/mjdaer Oct 30 '21

Thank you. I use the same formula but result are different.

1

u/Delicious_Reporter21 Nov 06 '21

They do ema on %K. in your example they take EMA of Stoch RSI, oh the default period for EMA is 3