回复 85楼 reedwu
经过几天的测试,程序很好,感谢sdta的大力支持,大家可以测试下,希望对大家的炒股有帮助,谢谢了。
需要说明的是先要在1a0001.dbf上增加一列trmd number(15,4),测试时只要修改 nday,nm,nn三个值,对应kdj的参数设置,然后累计profit值就是盈利值。
USE 1a0001.DBF ALIAS A
BLANK ALL FIELDS K,D,TRIX,TRMA,
trmd
G=100
H=100
nday=18
&&修改天数
nm=5
&&修改k参数
nn=4
&&修改d参数
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,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 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 TABLES
&&close all
USE kddk.dbf
n=2
GO n
DO WHILE !EOF()
a=shclose
GO n-1
b=shclose
GO n
REPLACE profit WITH a-b
SKIP
n=n+1
ENDDO
CLOSE TABLES
USE kddk.dbf
REPLACE ALL profit WITH 0 for trmekd>0
SELECT SUM(profit) FROM kddk WHERE shy>=2009 INTO ARRAY xx
?nday,nm,nn,xx &&求2009年以来的盈利
CLOSE TABLES
ERASE KD.DBF
ERASE DK.DBF
CLOSE ALL
[
本帖最后由 reedwu 于 2012-3-20 09:38 编辑 ]