door JOHAN M » zo 07 sep 2003, 8:26
Paul
Misschien kan dit je helpen ;
FUNCTIE ?:
value function zLinearRegValue (value xSeries[],value xNumberOfBars,value xWhichBar) begin
?value xI, xSumX,xSumX2, xNumX=0;
?if xNumberOfBars<>xNumX then begin
? ?xNumX := xNumberOfBars; ?xSumX := 0; ?xSumX2 := 0;
? ?for xI := 0 to xNumX-1 begin
? ? ?xSumX := xSumX+xI; ? ?
? ? ?xSumX2 := xSumX2+xI*xI; ? ?
? ? ?end;
? ?end;
?value xY, xSumY, xSumY2, xSumXY;
?xSumY := 0; ? ? xSumY2 := 0; ? ?xSumXY := 0;
?for xI := 0 to xNumX-1 begin
? ?xY := xSeries[xI];
? ?xSumY := xSumY+xY;
? ?xSumY2 := xSumY2+xY*xY;
? ?xSumXY := xSumXY+xI*xY;
? ?end; ? ?
?value xB2, xBeta, xAlpha;
?xB2 := xNumX*xSumX2-xSumX*xSumX;
?if xB2=0 then xB2 := 0.0001;
?xBeta := (xNumX*xSumXY-xSumX*xSumY)/xB2;
?xAlpha := (xSumY-xBeta*xSumX)/xNumX;
?zLinearRegValue := xAlpha+xBeta*xWhichBar;
end;
INDICATOR ? :
value function zLinearReg (value xSeries[]=Close,value xNumberOfBars=20) begin
?value xLinearReg;
?xLinearReg := zLinearRegValue(xSeries,xNumberOfBars,0);
?Plot1(xLinearReg,'LinReg'+NumToStr(xNumberOfBars));
?end;
JOHAN M