setposition(filled, market) 刪單交易指令不執行

  •   100 
  • 最後發表   Robert168  2022 十一月 15
Robert168 發文於   2022/11/14

小幫手 您好

最近一直在測試 卻發現setposition(filled, market) 刪單交易指令都不執行

可否幫我看看問題在哪邊?

if hasPosition then begin

if  c<filledAvgPrice*0.96 then begin

setposition(0);

alert("停利賣出"+numToStr(c,2)+"成本"+numToStr(filledAvgPrice,2));

end;

if hasPosition and c>filledAvgPrice*1.04 then begin

setposition(0);

alert("停損賣出"+numtostr(c,2)+"成本"+numToStr(filledAvgPrice,2));

end;     

             if CurrentTime>131000 and  hasPosition then  setposition(0);//開始平倉

if CurrentTime>131600 and CurrentTime<131800 then setposition(filled, market);//刪單

if CurrentTime>132200 and hasPosition then setposition(0,market);//市價清空部位  

end;

XQ小幫手 發文於   2022/11/15

 Hello Robert168,

 

小幫手會建議您在下交易指令時用 position 和 filled 來控管,並將相關數值 print 出來確認。

須注意多次執行 setposition 函數,系統只會執行第一個執行到的 setposition。

 

上面的腳本中 if CurrentTime>131000 and  hasPosition then  setposition(0); 因為是在 if hasPosition then begin 的條件式裡,所以一定會執行,那麼下面的

if CurrentTime>131600 and CurrentTime<131800 then setposition(filled, market);//刪單

if CurrentTime>132200 and hasPosition then setposition(0,market);//市價清空部位  

這兩行就算符合條件也不會執行,因為setposition(0)先被執行了。

  • 按讚來自於
  • r1171125
發表回覆
Close