回复 104楼 sdta
CLOSE TABLES
IF FILE('lsb.dbf')
DELETE FILE lsb.dbf
ENDIF
CREATE TABLE LSB (XH N(3),NDAY0 N(2),NM0 N(2),NN0 N(2),xx0 n(15,4))
FOR NDAY1=9 TO 10
FOR NM1=3 TO 4
FOR NN1=3 TO 4
INSERT INTO LSB VALUES(RECNO(),NDAY1,NM1,NN1,0)
ENDFOR
ENDFOR
ENDFOR
CLOSE TABLES &&以上建立lsb表,将要取值的变量列表
USE lsb.dbf
nx=1
GO nx
DO WHILE !EOF()
nday=nday0
nm=nm0
nn=nn0 &&分别从lsb表中将nday,nm,nn的值取过来
&&nday=18
&&修改天数
&&nm=5
&&修改k参数
&&nn=4
&&修改d参数,以下程序不变,直到skip
USE 1a0001.DBF ALIAS A
BLANK ALL FIELDS K,D,TRIX,TRMA,trmd
G=100
H=100
FOR I=1 TO RECCOUNT()-(nday-1)
SELECT MAX(SHHIGH),MIN(SHLOW) FROM 1A0001 WHERE BETWEEN(RECNO(),I,I+(nday-1)) INTO ARRAY AA
SELECT A
REPLACE K WITH AA(1,2),D WITH AA(1,1),TRIX WITH (ABS(shclose-k)/ABS(d-k))*100,TRMA WITH (TRIX+(nm-1)*G)/nm,TRMD WITH (TRMA+(nn-1)*H)/nn FOR RECNO()=I+(nday-1)
GO I+(nday-1)
G=TRMA
H=TRMD
ENDFOR
&&Close all
*----KD表
SELECT *,CAST("" AS Numeric(4)) AS TRME FROM 1A0001 WHERE trma>trmd INTO TABLE KD
B=SHNO
SCAN FOR RECNO()>1 AND !EOF()
A=SHNO
REPLACE TRME WITH A-B
B=SHNO
ENDSCAN
DELETE FOR TRME=1
PACK
*----DK表
SELECT *,CAST("" AS Numeric(4)) AS TRME FROM 1A0001 WHERE trma<trmd INTO TABLE DK
B=SHNO
SCAN FOR RECNO()>1 AND !EOF()
A=SHNO
REPLACE TRME WITH A-B
B=SHNO
ENDSCAN
DELETE FOR TRME=1
PACK
&&Close all
SELECT shno,shtime,shy,shm,shhigh,shlow,shclose,trma,trmd,CAST("" AS Numeric(4)) AS TRMEKD,CAST("" AS Numeric(4)) AS TRMEDK, CAST("" AS Numeric(15,4)) AS profit FROM 1A0001 WHERE shy>=2009 INTO TABLE KDDK
UPDATE KDDK SET TRMEKD=KD.TRME FROM KD WHERE KDDK.SHNO==KD.SHNO
UPDATE KDDK SET TRMEDK=DK.TRME FROM DK WHERE KDDK.SHNO==DK.SHNO
DELETE FOR (TRMEKD=0 AND TRMEDK=0) &&可以留着,这样数据都全
PACK
&&close all
USE kddk.dbf
GO TOP
b=shclose
SCAN FOR RECNO()>1 AND !EOF()
REPLACE profit WITH shclose-b
b=shclose
ENDSCAN
REPLACE ALL profit WITH 0 for trmekd>0
SELECT SUM(profit) FROM kddk
INTO ARRAY xx
?nday,nm,nn,xx &&这句也可以将xx写进lsb.dbf中的xx0中去,对应的的nx就是xh repl xx0 with xx for xh=nx 可能和下面的一样都没能找到 lsb表,所以都出错了
SKIP &&这里出错了,没能执行下去
nx=nx+1
ENDDO
CLOSE TABLES
CLOSE ALL