Much, much better, Brooke ;) Making pctgain divbyzero-proof also eliminates the bothersome b:= .0001+(num/den); kludge.
As I e-mailed you, the logic is simpler if j is stepped forward; assuming Roy will abide that, here is my version with the pctgain test and some minor cosmetic changes. -Bob -------------------- // Brooke's latest with j advancing, pctgain test, and close(j) //Back-testing version by Roy Yorgensen output = "linregslope.lst"; //input="3kVol.lst"; issuetype common; integer i,j, S, Sx; float b,lastB, Sxx, Sxy, Sy, pctgain; S := 21; daystoload = 50 + S ; daysrequired = 2 + 10 + S; //may need for newish issues lastB:= 9999; // large first time flag won't require testing for j = -10 to 0 do // reset all variables at start of i loop Sx := 0; Sxx := 0; Sxy := 0; Sy := 0; for i = j+(1 - S) to j do Sx := Sx + i; Sy := Sy + close(i); Sxx := Sxx + i*i; Sxy := Sxy + i*close(i); next i; b := (S*Sxy - Sx*Sy)/(S*Sxx - Sx*Sx); pctgain:= (b -lastb)/abs(lastb+.0000001)*100; if pctgain > 25 then println symbol,",", date(j),",",close(j):6:3,","," B: ", b:4:3,","," LastB: ", lastb:4:3,","," Pctgain: ", pctgain:4:2; endif; lastb:=b; // save current for pctgain next j; |