87 double rs = avgUp[0] / (avgDown[0] == 0 ? 1 : avgDown[0]);
88 double rsi = 100 - (100 / (1 + rs));
Line 87 of RSI indicator is incorrectly coded.
This line calculates rs and guards against the possibility of division by zero.
If true then rs equates to 1 which would result in rsi = 50, which is wrong.
The correct result is rsi = 100 if avgDown = 0.
Line 87 should be deleted and line 88 should be revised to:
double rsi = avgDown[0] == 0 ? 100 : 100 - (100/(1 + avgUp[0]/avgDown[0]));
Comment