限價停利沒成交,無法改成市價平倉,有高手可以幫幫我嗎???

  •   122 
  • 最後發表   羽毛的羽  2024 一月 14
羽毛的羽 發文於   2024/01/09

麻煩請小幫手協助一下....感恩

if Position <= -1 and Filled <= -1 then begin  //目前台指期持有空單1口 

       

if profit_point > 0 and close <= FilledAvgPrice - profit_point then begin //觸發停利價位

SetPosition(0, open - 10);//執行平倉,以開盤價 -10點掛單

end else if Position = 0 and TrueAll(Position <> Filled, 3) then begin 

SetPosition(0, market);  

 

我想要:經過3根K棒沒成交,則以範圍市價直接出場,可是我上面語法寫這樣卻沒有刪單,導致當沖單變成會留倉到隔日開盤出場

排序方式: 標準 | 最新
XS小編 發文於   2024/01/12

Hello 羽毛的羽,

 

您的這種寫法 (if ... else if ...) 會讓腳本先執行if 的內容,除非if的內容不符合時才會執行 else if 的內容。

且在執行 SetPosition(0, open - 10); 後 if Position <= -1 and Filled <= -1 就不會再符合。

當同時有複數setposition符合時,腳本只會執行第一個setposition指令。

要注意 begin ... end 所包含的區塊。

 

小編會建議修改為:

if filled <= -1 then begin

    if profit_point > 0 and close <= FilledAvgPrice - profit_point and position <= -1 then begin //觸發停利價位

        SetPosition(0, open - 10);//執行平倉,以開盤價 -10點掛單

        end;

 

    if Position = 0 and TrueAll(Position <> Filled and Filled <= -1, 3) then SetPosition(0, market);    //下出停利單後3根沒有成交就市價出場

    end;

羽毛的羽 發文於   2024/01/14

謝謝回覆,我在試試看

發表回覆
Close