It looks like you're new here. If you want to get involved, click one of these buttons!

`public static double getRSI(List<Candle> candles){`

double avgU = 0;

double avgD = 0;

int N = candles.size();

for(int i = 0;i <N-1;i++){

double delta = candles.get(i+1).getClose() - candles.get(i).getClose();

if(delta < 0)

avgD += Math.abs(delta);

else

avgU += delta;

}

avgU = avgU/(N-1);

avgD = avgD/(N-1);

if(avgD == 0)

return 100.0;

double rs = avgU/avgD;

double rsi = 100 - 100/(1 + rs);

return rsi;

}

Please tell me where i am wrong.
1) Can you match your RSI values with the actual RSI from the beginning of a stock price?

2) You can try to take the previous Average up/ average down and multiply it with N-1 and add to the current Up/down values to calculate the current average up/down values.

The tried the above two things and i was able to get the same RSI values which Zerodha produces.