后臺程式化同一根K線走完后,為何會開兩次倉?
作者:金字塔 來源:cxh99.com 發布時間:2016年12月25日
- 咨詢內容:
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)?