整个后台程序的代码都贴在下面。代码中有许多debugfile输出,输出的txt也贴在下面。从txt中可以看出来,在14:55:07.341的时候,5c本来是-4的,表示PTA已经持空仓4手,但是在14:55:07.845的时候,5c莫名其妙变成0了,就是这个导致了在PTA第五组参数上的重复下单,又再下了4手空单。之前的4手空单是14:54:22下的。
WARNING_DISABLE:4;
INPUT: ATRN(15,5,150,1);
INPUT: INISTOP(0.5,0.2,2,0.1);
INPUT: 1ent(0.4,0.1,1.5,0.2);
INPUT: 1ext(2.0,0.5,5,0.3);
INPUT: 1inir(0.001,0,0.03,0.001);
INPUT: 2ent(0.55,0.1,1.5,0.2);
INPUT: 2ext(2.5,0.5,5,0.3);
INPUT: 2inir(0.001,0,0.03,0.001);
INPUT: 3ent(0.7,0.1,1.5,0.2);
INPUT: 3ext(3,0.5,5,0.3);
INPUT: 3inir(0.001,0,0.03,0.001);
INPUT: 4ent(0.85,0.1,1.5,0.2);
INPUT: 4ext(3.6,0.5,5,0.3);
INPUT: 4inir(0.001,0,0.03,0.001);
INPUT: 5ent(1.0,0.1,1.5,0.2);
INPUT: 5ext(4.2,0.5,5,0.3);
INPUT: 5inir(0.001,0,0.03,0.001);
1c:= extgbdata('PTA1c');
1p:= extgbdata('PTA1p');
1j:= extgbdata('PTA1j');
2c:= extgbdata('PTA2c');
2p:= extgbdata('PTA2p');
2j:= extgbdata('PTA2j');
3c:= extgbdata('PTA3c');
3p:= extgbdata('PTA3p');
3j:= extgbdata('PTA3j');
4c:= extgbdata('PTA4c');
4p:= extgbdata('PTA4p');
4j:= extgbdata('PTA4j');
5c:= extgbdata('PTA5c');
5p:= extgbdata('PTA5p');
5j:= extgbdata('PTA5j');
atr:= stkindi('', 'truedayrange.matr1',0,6);
closeyd:= callstock(stklabel, vtclose, 6, -1);
ou1:= closeyd + 1ent * atr;
od1:= closeyd - 1ent * atr;
ou2:= closeyd + 2ent * atr;
od2:= closeyd - 2ent * atr;
ou3:= closeyd + 3ent * atr;
od3:= closeyd - 3ent * atr;
ou4:= closeyd + 4ent * atr;
od4:= closeyd - 4ent * atr;
ou5:= closeyd + 5ent * atr;
od5:= closeyd - 5ent * atr;
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','开始1c=%.0f',1c);
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','开始2c=%.0f',2c);
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','开始3c=%.0f',3c);
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','开始4c=%.0f',4c);
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','开始5c=%.0f',5c);
//品种内第1套参数的交易代码
(注:这些代码与下面第五组完全相同,只是编号改了,为避免太长,就删去了)
//品种内第2套参数的交易代码
//品种内第3套参数的交易代码
//品种内第4套参数的交易代码
//品种内第5套参数的交易代码
if 5c > 0 then begin
if close > 5j then 5j := close; //更新极值
if (5j - 5ext * atr) > 5p then 5p := 5j - 5ext * atr; //更新平仓价格
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','tsell前5p=%.0f',5p); (注:该行代码在第四套漏了没加上,故PTA.txt会看不见这行输出,但是第1、2、3套都有)
if close <= min(ceiling(ou5),ceiling(5p)) then begin //平仓并清零所有全局变量
tsell(1, 5c, mkt);
5j := 0;
5p := 0;
5c := 0;
end;
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','tsell后5c=%.0f',5c);
extgbdataset('PTA5c', 5c);
extgbdataset('PTA5p', 5p);
extgbdataset('PTA5j', 5j);
end;
if 5c < 0 then BEGIN
if close < 5j then 5j := close; //更新极值
if (5j + 5ext * atr) < 5p then 5p := 5j + 5ext * atr; //更新平仓价格
if close >= max(floor(od5),floor(5p)) then begin
tsellshort(1, abs(5c), mkt);
5j := 0;
5p := 0;
5c := 0;
end;
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','tsellshort后5c=%.0f',5c);
extgbdataset('PTA5c', 5c);
extgbdataset('PTA5p', 5p);
extgbdataset('PTA5j', 5j);
end;
if 5c = 0 then begin
if close >= floor(ou5) then begin
5j := close;
5p := close - inistop * atr;
5c := round((tasset * 1inir) / (inistop * atr * MULTIPLIER));
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','tbuy前5c=%.0f',5c);
tbuy(1, 5c, mkt);
extgbdataset('PTA5c', 5c);
extgbdataset('PTA5p', 5p);
extgbdataset('PTA5j', 5j);
end;
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','tbuy后5c=%.0f',5c);
if close <= ceiling(od5) then begin
5j := close;
5p := close + inistop * atr;
5c := round((tasset * 1inir) / (inistop * atr * MULTIPLIER));
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','tbuyshort前5c=%.0f',5c);
tbuyshort(1, 5c, mkt);
extgbdataset('PTA5c', -5c);
extgbdataset('PTA5p', 5p);
extgbdataset('PTA5j', 5j);
end;
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','tbuyshort后5c=%.0f',5c);
end;
debugfile('C:\Users\95\Desktop\New Folder\程序化\debugfile\PTA.txt','PTA运行结束',0);
-----------------------------------------------------------------------------------------------------------------
2016-04-15 14:55:07.087 开始1c=4
2016-04-15 14:55:07.089 开始2c=4
2016-04-15 14:55:07.091 开始3c=4
2016-04-15 14:55:07.093 开始4c=4
2016-04-15 14:55:07.093 开始5c=-4
2016-04-15 14:55:07.094 tsell前1p=4792
2016-04-15 14:55:07.094 tsell后1c=4
2016-04-15 14:55:07.095 tsell前2p=4770
2016-04-15 14:55:07.095 tsell后2c=4
2016-04-15 14:55:07.098 tsell前3p=4783
2016-04-15 14:55:07.098 tsell后3c=4
2016-04-15 14:55:07.099 tsell后4c=4
2016-04-15 14:55:07.101 tsellshort后5c=-4
2016-04-15 14:55:07.103 PTA运行结束
2016-04-15 14:55:07.335 开始1c=4
2016-04-15 14:55:07.335 开始2c=4
2016-04-15 14:55:07.336 开始3c=4
2016-04-15 14:55:07.336 开始4c=4
2016-04-15 14:55:07.337 开始5c=-4
2016-04-15 14:55:07.337 tsell前1p=4792
2016-04-15 14:55:07.338 tsell后1c=4
2016-04-15 14:55:07.338 tsell前2p=4770
2016-04-15 14:55:07.339 tsell后2c=4
2016-04-15 14:55:07.340 tsell前3p=4783
2016-04-15 14:55:07.340 tsell后3c=4
2016-04-15 14:55:07.341 tsell后4c=4
2016-04-15 14:55:07.341 tsellshort后5c=-4
2016-04-15 14:55:07.341 PTA运行结束
2016-04-15 14:55:07.845 开始1c=4
2016-04-15 14:55:07.846 开始2c=4
2016-04-15 14:55:07.846 开始3c=4
2016-04-15 14:55:07.847 开始4c=4
2016-04-15 14:55:07.847 开始5c=0
2016-04-15 14:55:07.848 tsell前1p=4792
2016-04-15 14:55:07.848 tsell后1c=4
2016-04-15 14:55:07.849 tsell前2p=4770
2016-04-15 14:55:07.850 tsell后2c=4
2016-04-15 14:55:07.851 tsell前3p=4783
2016-04-15 14:55:07.851 tsell后3c=4
2016-04-15 14:55:07.852 tsell后4c=4
2016-04-15 14:55:07.852 tbuy后5c=0
2016-04-15 14:55:07.852 tbuyshort前5c=4
2016-04-15 14:55:07.854 tbuyshort后5c=4
2016-04-15 14:55:07.854 PTA运行结束
2016-04-15 14:55:08.357 开始1c=4
2016-04-15 14:55:08.358 开始2c=4
2016-04-15 14:55:08.358 开始3c=4
2016-04-15 14:55:08.359 开始4c=4
2016-04-15 14:55:08.359 开始5c=-4
2016-04-15 14:55:08.360 tsell前1p=4792
2016-04-15 14:55:08.360 tsell后1c=4
2016-04-15 14:55:08.360 tsell前2p=4770
2016-04-15 14:55:08.361 tsell后2c=4
2016-04-15 14:55:08.362 tsell前3p=4783
2016-04-15 14:55:08.363 tsell后3c=4
2016-04-15 14:55:08.363 tsell后4c=4
2016-04-15 14:55:08.363 tsellshort后5c=-4
2016-04-15 14:55:08.364 PTA运行结束
2016-04-15 14:55:08.845 开始1c=4
2016-04-15 14:55:08.846 开始2c=4
2016-04-15 14:55:08.847 开始3c=4
2016-04-15 14:55:08.847 开始4c=4
2016-04-15 14:55:08.848 开始5c=-4
2016-04-15 14:55:08.848 tsell前1p=4792
2016-04-15 14:55:08.849 tsell后1c=4
2016-04-15 14:55:08.849 tsell前2p=4770
2016-04-15 14:55:08.849 tsell后2c=4
2016-04-15 14:55:08.850 tsell前3p=4783
2016-04-15 14:55:08.850 tsell后3c=4
2016-04-15 14:55:08.851 tsell后4c=4
2016-04-15 14:55:08.851 tsellshort后5c=-4
2016-04-15 14:55:08.851 PTA运行结束