各位老师,我的这个后台自动化交易不会平仓,只会开仓,麻烦各位给修改一下,并说明问题出在什么地方,先行谢过,代码如下:
资产:TASSET,LINETHICK0;
可用现金:TCASH,LINETHICK0;
持仓:THOLDING,LINETHICK0;
//准备中间变量
B:=MA(C,5),COLORWHITE;
D:=MA(C,20),COLORGREEN;
S:=CROSS(B, D);
X:=CROSS(D,B);
//建立多头条件
long:=S and time>090020 and time<145200;
if long then
begin {要先平仓,再开仓}
tsellshort(long,tholding<0,0,lmt,c),ORDERQUEUE;
tbuy(long,1,lmt,c),ORDERQUEUE;
end
//建立空头条件
short:=X and time>090020 and time<145200;
if short then
begin {要先平仓,再开仓}
tsell(short,tholding>0,0,lmt,c),ORDERQUEUE;
tbuyshort(short,1,lmt,c),ORDERQUEUE;
end
//收盘前平仓
tsell(time>145500 and tholding>0,0,lmt,c);
tsellshort(time>145500 and tholding<0,0,lmt,c);
http://www.weistock.com/bbs/dispbbs.asp?boardid=4&Id=332
看问题15
此外,告诫初级用户,使用DEBUGFILE调试你的代码是最基础的基本要求,连这个都不知道的或者不会用的,不要随便上来就用后台自动交易,以免给你后面的工作带来不快乐。
楼主的多头空头平仓语句有问题。如:
tsellshort(long,tholding<0,0,lmt,c),ORDERQUEUE;
应改成: tsellshort(long and tholding<0,0,lmt,c),ORDERQUEUE;
另外,如果是模拟的,可能有一分钟延迟,建议把开仓时间改为090100---145200