different result when Calculate RSI from excel sheet or from web link
excel sheet formulas
=IF(B3>B4,ABS(B3-B4),0)
=IF(B3<B4,ABS(B3-B4),0)
=(D32/(F$2+1))+(F4(1-(2/(F$2+1))))
=(E32/(G$2+1))+(G4(1-(2/(G$2+1))))
=100-(100/(1+(F3/G3)))
code in AB as excel sheet formulas
arryexl=Close;
perRSEX= Param( "Periods", 14, 2, 200, 1 );
CU=IIf( Close > Ref(Close, -1), abs(arryexl), 0); //Positive close
CD=IIf( Close < Ref(Close, -1), abs(arryexl), 0); // Negative close
UpLength =(CU*(2/(perRSEX+1)))+((Ref(CU,-1)*(1-(2/(perRSEX+1)))));
DownLength=(CD*(2/(perRSEX+1)))+((Ref(CD,-1)*(1-(2/(perRSEX+1)))));
rsiexl=100-(100/(1+(UpLength/DownLength)));
link for RSI formula
https://www.incrediblecharts.com/indicators/rsi_relative_strength_index.php
code in AB as link for RSI formula
arry = Close ; /// ///
perRS= Param( "Periods", 14, 2, 200, 1 );
Parry =IIf( Close > Ref(Close, -1), abs(arry), 0); //Positive close
Narry = IIf( Close < Ref(Close, -1), abs(arry), 0); // Negative close
totalup=Sum(Parry, perRS);
testdw=Sum(Narry, perRS);
avgup=EMA(totalup,perRS);
avgdw=EMA(testdw,perRS);
R_S= avgup/avgdw ;
TESTRSI= 100-(100/(1+R_S));
AB RSI built in
REALRSI=RSI(perRS);
but the result is different
what is the right formula for RSI without using loop
full code
_SECTION_BEGIN("RSi test ");
arryexl=Close;
perRSEX= Param( "Periods", 14, 2, 200, 1 );
CU=IIf( Close > Ref(Close, -1), abs(arryexl), 0); //Positive close
CD=IIf( Close < Ref(Close, -1), abs(arryexl), 0); // Negative close
UpLength =(CU*(2/(perRSEX+1)))+((Ref(CU,-1)*(1-(2/(perRSEX+1)))));
DownLength=(CD*(2/(perRSEX+1)))+((Ref(CD,-1)*(1-(2/(perRSEX+1)))));
rsiexl=100-(100/(1+(UpLength/DownLength)));
arry = Close ; /// ///
perRS= Param( "Periods", 14, 2, 200, 1 );
Parry =IIf( Close > Ref(Close, -1), abs(arry), 0); //Positive close
Narry = IIf( Close < Ref(Close, -1), abs(arry), 0); // Negative close
totalup=Sum(Parry, perRS);
testdw=Sum(Narry, perRS);
avgup=EMA(totalup,perRS);
avgdw=EMA(testdw,perRS);
R_S= avgup/avgdw ;
TESTRSI= 100-(100/(1+R_S));
REALRSI=RSI(perRS);
Filter=1;
AddColumn(Close,"Close",1.2);
AddColumn(TESTRSI,"TESTRSI",1.2);
AddColumn(REALRSI,"REALRSI",1.2);
AddColumn(rsiexl,"rsiexl",1.2);
Plot( TESTRSI, "TESTRSI",colorBlack, styleLine | styleThick );
Plot( REALRSI, "REALRSI",colorBlack, styleLine | styleThick );
_SECTION_END();
thank you