RSI indicator

ashishjindal89
I am trying to calculate the RSI values but they are not matching with zerodha's RSI. I am using following algo to compute RSI :
public static double getRSI(List 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.
Sign In or Register to comment.