當沖策略,但盤前盤後自動交易中心確有部位

  •   52 
  • 最後發表   whw  2025 七月 22
whw 發文於   2025/07/21

如題

盤前盤後啟動策略本應該是當沖策略但卻有部位

想請問可能是哪邊有問題

謝謝

附加文件

排序方式: 標準 | 最新
虎科大許教授 發文於   2025/07/21

會不會你設定132500出場,但已進入試撮,沒有洗價,造成留倉?

whw 發文於   2025/07/22

謝謝教授回覆

但我其它支策略也是用相同的出場,卻沒有這樣的問題

我出場改成

IF currenttime >= 132000  then begin 

    setPosition(0);

   end;

也還是會有留倉

虎科大許教授 發文於   2025/07/22

可能要看完整的腳本才找得到問題。

whw 發文於   2025/07/22

 

var: kbar(0),nonprofitbar(0);    

var:hbar(0),lbar(0);    

var:upperline(0);    

var:barsinceentry(0);    

var:highdc(0);    

var:nohigherbar(0);    

var: sflag(0);    

    

    

var: orderprice(0);//預期委託價格    

var:orderqty(0);//換算後數量    

var: ordersizew(20);//部位幾萬   

input: kbarofsflag(5), inpercent(5); 

orderprice=addSpread(opend(0),1);    

orderqty=(ordersizew*10000)/(orderprice*1000);    

 

//參數歸0    

if date<>date[1] then begin   

kbar=0;    

barsinceentry=0;    

highdc=0;    

sflag=0;    

end;    

    

if time>=090000 then begin    

kbar=kbar+1;    

if h=highd(0) then hbar=kbar;    

if l=lowd(0) then lbar=kbar;    

end;    

    

    

if time=090000 and c>o then begin    

sflag=1;    

value1=h;    

end;    

if kbar=kbarofsflag and sflag=1 and c>value1 then sflag=2;  

  

condition99=

 c>maxlist(c[1],o) 

and sflag=iff(opend(0)>opend(1),1,1)

 

;

 

 

 

if position=0     

and filled=0    

and kbar>1

and kbar<120    

and c<closed(1)*(1+0.01*inpercent)

and opend(0)>lowd(1)

and opend(0)<highd(1)

and getsymbolInfo("買賣現沖") and getsymbolInfo("可放空")  

and condition99[1]

and not GetField("處置股", "D") 

then setposition(-orderqty-iff(opend(0)>100 and opend(0)<150,1,0),addSpread(c,-1));                            

                                

condition98=c>o;

 

if position[1]<>0 and kbar>5  and kbar<60 and c<filledAvgPrice and highd(0)<highd(1)  and highd(0)<closed(1)*1.07 and condition98[1] then begin

setposition(-orderqty*2,market);     

end;        

    

if position<0 then begin     

barsinceentry=barsinceentry+1;    

if c>closed(1)*1.07 then setposition(0,market); 

if c<=GetField("收盤價","d")[1]*0.9 then begin        

setposition(0,market);        

end;        

        

if c>GetField("收盤價","d")[1]*1.9 then begin        

setposition(0,market);        

end;        

   

//收盤前出場        

input:exitperiod(5);        

var:marketclosecondition(false);        

marketclosecondition=entermarketCloseTime(exitperiod);        

        

if marketclosecondition then begin        

setposition(0,market);       

end;        

end;

虎科大許教授 發文於   2025/07/22

(1)當沖策略的策略部位不應該選擇由腳本計算,應該使用不設定。

(2)逐筆洗價之下,不應該用value1變數,而應該宣告intrabarpersist的變數。

收盤前出場的程式應該是沒問題。收盤前沒平倉,原因可能是由腳本計算造成。改成不設定,應該就沒這個問題了。

whw 發文於   2025/07/22

謝謝教授幫忙!希望還能再開課!

 

發表回覆
Close