梳理了一遍代码,除了需要将你的代码中很多复制语句,需要将=换成:=外,从代码逻辑上未发现问题。只能在实际运行中,加入debugfile调试函数来跟踪了,后台程序化交易基本都要靠调试函数来跟踪问题的,单看代码是看不出什么问题的,只能发现一些简单的编写错误。以下是替你修改完的赋值语句错误。建议在实际运行的时候,用debugfile跟踪调试问题。
fangxiang:=1;
shijian:=111500;
riqi:=210202;
zhiying:=4000;
ctshoushu1:=1;
ctshoushu2:=2;
ctshoushu3:=3;
ctshoushu4:=4;
ctshoushu5:=5;
ctshoushu6:=6;
ctshoushu7:=7;
ctshoushu8:=8;
ctshoushu9:=9;
ctshoushu10:=10;
ctzhisun1:=10000;
ctzhisun2:=10000;
ctzhisun3:=10000;
ctzhisun4:=10000;
ctzhisun5:=10000;
ctzhisun6:=10000;
ctzhisun7:=10000;
ctzhisun8:=10000;
ctzhisun9:=10000;
ctzhisun10:=10000;
GLOBALVARIABLE:ct:=1;//默认从1开始
GLOBALVARIABLE:ctshoushu:=1;
GLOBALVARIABLE:ctzhisun:=1;
GLOBALVARIABLE:fangxiangs:=0;
//*****************************
账户:'1000';
套利品种1:'IF11';
套利品种2:'IF12';
//*****************************
dyk1:=dynainfo2(7,套利品种1)-TAVGENTERPRICEEX2('',套利品种1,0);//多盈亏
dyk2:=dynainfo2(7,套利品种2)-TAVGENTERPRICEEX2('',套利品种1,0);//多盈亏
kyk1:=TAVGENTERPRICEEX2('',套利品种1,1)-dynainfo2(7,套利品种1);//空盈亏
kyk2:=TAVGENTERPRICEEX2('',套利品种2,1)-dynainfo2(7,套利品种2);//空盈亏
yingkui:=dyk1+dyk2+kyk1+kyk2;
if ct=1 then
begin
ctzhisun:=ctzhisun1;
ctshoushu:=ctshoushu1;
end
if riqi>date-1000000 or (riqi=date-1000000 and shijian>=time) and fangxiangs=0 then
begin
if fangxiang=1 then
begin
TBUYSHORT(1,ctshoushu,MKT ,0,0,账户,套利品种1);
TBUY(1,ctshoushu,MKT ,0,0,账户,套利品种2);
fangxiangs:=1;
end
if fangxiang=-1 then
begin
TBUYSHORT(1,ctshoushu,MKT ,0,0,账户,套利品种2);
TBUY(1,ctshoushu,MKT ,0,0,账户,套利品种1);
fangxiangs:=-1;
end
end
if yingkui>zhiying then
begin
TSELL(1,ct,MKT ,0,0,账户,套利品种1);
TSELL(1,ct,MKT ,0,0,账户,套利品种2);
TSELLSHORT(1,ct,MKT ,0,0,账户,套利品种1);
TSELLSHORT(1,ct,MKT ,0,0,账户,套利品种2);
ct:=1;//连续止损中断的地方,务必重置全局变量CT。这里是止盈的地方重置了,你如果还有其他地方要终止连续止损的统计,同样也要重置这个全局变量
fangxiangs:=2;
end
if yingkui<ctzhisun then
begin
//平仓语句
ct:=ct+1;//止损的地方累计这个全局变量的值
//在反手的语句里,可以直接用ct作为反手下单的手数
if ct=2 then
begin
ctzhisun:=ctzhisun2;
ctshoushu:=ctshoushu2;
end
if ct=3 then
begin
ctzhisun:=ctzhisun3;
ctshoushu:=ctshoushu3;
end
if ct=4 then
begin
ctzhisun:=ctzhisun4;
ctshoushu:=ctshoushu4;
end
if ct=5 then
begin
ctzhisun:=ctzhisun5;
ctshoushu:=ctshoushu5;
end
if ct=6 then
begin
ctzhisun:=ctzhisun6;
ctshoushu:=ctshoushu6;
end
if ct=7 then
begin
ctzhisun:=ctzhisun7;
ctshoushu:=ctshoushu7;
end
if ct=8 then
begin
ctzhisun:=ctzhisun8;
ctshoushu:=ctshoushu8;
end
if ct=9 then
begin
ctzhisun:=ctzhisun9;
ctshoushu:=ctshoushu9;
end
if ct=10 then
begin
ctzhisun:=ctzhisun10;
ctshoushu:=ctshoushu10;
end
if fangxiangs=1 then
begin
TBUYSHORT(1,ctshoushu,MKT ,0,0,账户,套利品种1);
TBUY(1,ctshoushu,MKT ,0,0,账户,套利品种2);
fangxiangs:=-1;
end
if fangxiangs=-1 then
begin
TBUYSHORT(1,ctshoushu,MKT ,0,0,账户,套利品种2);
TBUY(1,ctshoushu,MKT ,0,0,账户,套利品种1);
fangxiangs:=1;
end
end