door Paul M » do 06 nov 2003, 23:25
Hallo Rogier,
Dat ligt aan de functie RSI.
Ik heb de naam omgedoopt naar zRSI.
Functie:
value function zRSI (value xSeries[],value xNumberOfbars) begin
?{---- variables used ----}
?value xUp[],xDown[],xUpAvg[],xDownAvg[],xI,xChange[];
?{---- if first time, kick-start the calculation ----}
?if CurrentBar=1 or xUpAvg[1]=_NA or xDownAvg[1]=_NA then begin
? ?for xI := xNumberOfBars-1 downto 0 do begin
? ? ?xChange := xSeries[xI]-xSeries[xI+1];
? ? ?if xChange>0 then xUp[xI] := xChange else xUp[xI] := 0;
? ? ?if xChange<0 then xDown[xI] := -xChange else xDown[xI] := 0;
? ? ?end;
? ?xUpAvg := Average(xUp,xNumberOfBars);
? ?xDownAvg := Average(xDown,xNumberOfBars);
? ?end
?{---- else calculate new up and down value ----}
?else begin
? ?xChange := xSeries-xSeries[1];
? ?if xChange>0 then xUp := xChange else xUp := 0;
? ?if xChange<0 then xDown := -xChange else xDown := 0;
? ?xUpAvg := ((xNumberOfBars-1)*xUpAvg[1]+xUp)/xNumberOfbars;
? ?xDownAvg := ((xNumberOfBars-1)*xDownAvg[1]+xDown)/xNumberOfBars;
? ?end;
?{---- now calculate relative strength up and down ----}
?if xDownAvg=0 and xUpAvg=0 then zRSI := _NA
?else if xDownAvg=0 then zRSI := 100
?else zRSI := 100-100/(xUpAvg/xDownAvg+1);
?end;
Indicator:
Input: ?RSILen(13), LBLen(8), WAvgLen(5),Overbought(70),Oversold(30);
Var: ?RS(0),RSIL(0),RSIH(0),StochRSI(0),xRSI(0);
RS=zRSI(C,RSILen);
RSIL = Lowest(RS,LBLen);
RSIH = Highest(RS,LBLen);
StochRSI = (RS - RSIL)/(RSIH-RSIL);
xRSI=(WAverage(StochRSI,WavgLen))*100;
Plot1(xRSI,"Stoch RSI");
Plot2(OverBought, "OverBought");
Plot3(OverSold, "OverSold");
end;
Paul.