Chg = Price - Price[1]; Gain = 0; loss = 0; if (Chg>0) then gain = Chg else begin loss = Chg; end; if (Chg[1]>0) then gain = gain + Chg[1] else begin loss = loss + Chg[1]; end; if (loss<>0) then RS = gain/loss else begin; RS = -999999999; end; CurrRSI = 100-(100/(1-RS)); SmRSI = Average(CurrRSI, Period); ExRSI = xAverage(CurrRSI, Period);
2 comments:
Excellent work.
Have a nice week.
Code for RSI
inputs:
Price(Close),
Center(50),
OverSold( 20),
OverBought( 80),
Period(2);
variables: SmRSI( 0 ),
ExRSI(0),
Chg(0),
Gain(0),
Loss(0),
RS(0),
CurrRSI(0);
Chg = Price - Price[1];
Gain = 0; loss = 0;
if (Chg>0) then gain = Chg
else begin
loss = Chg;
end;
if (Chg[1]>0) then gain = gain + Chg[1]
else begin
loss = loss + Chg[1];
end;
if (loss<>0) then RS = gain/loss
else begin; RS = -999999999; end;
CurrRSI = 100-(100/(1-RS));
SmRSI = Average(CurrRSI, Period);
ExRSI = xAverage(CurrRSI, Period);
Plot1(SmRSI, "Simple");
Plot2(ExRSI, "Exp");
Plot3( Center, "Center");
Plot91(OverSold, "OverSold");
Plot92(OverBought, "OverBought");
Post a Comment