if duo and extgbdata(stklabel+'bn1')=0 then begin
tbuy(1,手数,mkt);
extgbdataset(stklabel+'bn1',1);
extgbdataset(stklabel+'bn15',手数);
extgbdataset(stklabel+'bdcs',0);
end
s:=ref(15atr,tenterbars);
if duo and extgbdata(stklabel+'bn1')=1 and c>=tENTERPRICE+zc*s then begin
tbuy(1,手数,mkt);
extgbdataset(stklabel+'bn1',2);
extgbdataset(stklabel+'bn152',手数);
extgbdataset(stklabel+'bdcs',0);
end
s:=ref(15atr,tenterbars);
程式刚开始运行时,达到条件只按“手数”开仓,只偶尔有同一根K线走完后开两倍手数的仓位,并且是同一时间重复开仓,现在经常是这样了,是什么原因。我的策略是限制达到条件只开一次仓,加一次仓,但是加仓是至少在下一根K线以后,因为是需要价格离第一次开仓有一定的距离了,再加仓的。现在经常这样,同一时间开了两倍手数的仓位后,等后面达到条件了,也不会加仓了。这到底是什么原因。
这两句中间sleep个1秒。在第一个开仓没报出去之前会获取到之前一个开仓价,中间sleep保证第一个开仓已经报出去了,在第二个开仓时获取的是第一个的开仓价
if duo and extgbdata(stklabel+'bn1')=0 then begin
tbuy(1,手数,mkt);
extgbdataset(stklabel+'bn1',1);
extgbdataset(stklabel+'bn15',手数);
extgbdataset(stklabel+'bdcs',0);
end
s:=ref(15atr,tenterbars);
sleep(1000);
if duo and extgbdata(stklabel+'bn1')=1 and c>=tENTERPRICE+zc*s then begin
tbuy(1,手数,mkt);
extgbdataset(stklabel+'bn1',2);
extgbdataset(stklabel+'bn152',手数);
extgbdataset(stklabel+'bdcs',0);
end
s:=ref(15atr,tenterbars);
就在开仓与加仓之间加一句代码就可以了,sleep(1000)?
if duo and extgbdata(stklabel+'bn1')=0 then begin
tbuy(1,手数,mkt);
extgbdataset(stklabel+'bn1',1);
extgbdataset(stklabel+'bn15',手数);
extgbdataset(stklabel+'bdcs',0);
sleep(1000);
end
s:=ref(15atr,tenterbars);
if duo and extgbdata(stklabel+'bn1')=1 and c>=tENTERPRICE+zc*s then begin
tbuy(1,手数,mkt);
extgbdataset(stklabel+'bn1',2);
extgbdataset(stklabel+'bn152',手数);
extgbdataset(stklabel+'bdcs',0);
end
那这样改,在开仓时进行sleep
又有问题,改过运行策略时,卡得不行了,以前一点都不卡的,
看来不能通过sleep来进行了
你上面开两次仓时,调试过没?用debugfile来输出一下,看看是不是你写的两个开仓语句,各下的一次