停損停利問題

  •   231 
  • 最後發表   AndyJian  2023 十月 19
AndyJian 發文於   2023/10/15

以下是我的移動停損停利的寫法,但我發現有些問題。

1.停損有些單會大大的超過停損設定點數(非周末留倉)。

2.有避免周末不留倉,但有些時候還是會沒有出場,進而導致跳空大停損的狀況。

想請問是寫法有問題嗎?

input: profit_point1(70, "停利(點)") , profit_point2(130, "停利(點)") ;

input: loss_point(50, "停損(點)");

 

if loss_point = 0 then raiseruntimeerror("請設定停損(點)");

 

if Position >= 1 then begin

{ 依照成本價格設定停損/停利 }

var: intrabarpersist stoploss_point(0);

 

{ 計算停損價格 }

if stoploss_point = 0 then begin

stoploss_point = FilledAvgPrice - loss_point;

end;

 

{ 如果價格上漲的話, 則往上挪動停損價格. 停損價格只會越來越高 }

if Close > FilledAvgPrice then begin

if Close - loss_point > stoploss_point then begin

stoploss_point = Close - loss_point;

end;

end;

if Close <= stoploss_point  then begin

{ 停損 }

SetPosition(0,market);

stoploss_point = 0;

end else begin

 

if profit_point1 > 0 and Close >= FilledAvgPrice + profit_point1 and Position = 2 and Filled = 2 then begin

{ 兩口單時停利1口 }

SetPosition(1,market);

 

end else if profit_point2 > 0 and Close >= FilledAvgPrice + profit_point2 and Position = 1 and Filled = 1 then begin

SetPosition(0,market);

stoploss_point = 0;

 

end else if DayOfWeek(Date) = 6 and currentTime >=044000 then begin {周末不留倉}

setposition(0,market);

stoploss_point = 0;

end;

end;

   end;

end;

ex:

 

 

XQ小幫手 發文於   2023/10/19

Hello AndyJian,

 

文章中腳本中最下方多了一個end,除此之外看起來應該是沒有問題。

您可以將相關數值print出來確認。

另外需注意交易指令如 setposition 等腳本一次運作中只會執行第一個運作到的,所以若腳本前方有其他的交易指令觸發的話,這部分的停損停利就不會執行。

 

若還是有問題的話,麻煩提供 交易腳本、回測設定 (截圖或報告皆可) 以及 XQ Log 來檢驗。

Log資料夾(預設路徑:C:\SysJust\XQLite\LOG)直接壓縮後提供即可。

您可以直接將檔案上傳,如果檔案過大的話也可以保存到雲端後將連結Mail至客服信箱 XQservice@XQ.com.tw 且務必附上 討論文章連結網址(小幫手才能盡早處理)。

感謝。

發表回覆
Close