下單進場執行 SetPosition(1)成功, 為何Position仍然為0

  •   146 
  • 最後發表   金牛俠客  2024 六月 05
金牛俠客 發文於   2024/05/31

var: intraBarPersist tran_status(0);

if position = 0 and filled = 0 then begin

   if long_condition and tran_status=0 then begin

      SetPosition(1);

      tran_status = 1;

   end;

end else if position <> 0 and filled <> 0 then begin

   if exit_condition and tran_status=1 then begin

      SetPosition(0);

      tran_status = 0;

   end;

end;

排序方式: 標準 | 最新
虎科大許教授 發文於   2024/05/31

Setposition(1),Position會變成1,除非又setposition(0),否則position不會變0。

金牛俠客 發文於   2024/05/31

剛剛回測已OK, 謝謝。

XS小編 發文於   2024/06/05

Hello 金牛俠客,

 

您可以在腳本中使用 print 確認當次執行時的 position 數值為何。

另外需注意,position 在同一次腳本執行中是不會改變的,所以就算當次執行有呼叫 setposition,position的數值也不會馬上改變,而是腳本執行完後才改變。

可以參考 XSHelp 裡的說明。

 

感謝 虎科大許教授 的熱心回覆。

發表回覆
Close