如何寫若達到一定的損益自動出清?

  •   444 
  • 最後發表   莊莊  2024 十一月 27
莊莊 發文於   2024/11/22

寫了一段自動交易程式,想在如果當下時間為 10:00 後,則計算虧損若超過 2000 元則自動出清平倉出場,但是在回測時總是試不出來,也是要到最後每日部位出零,請問語法是否有要修正的地方呢?

variable: cost_price(0), current_profit(0);

if Filled > 0 then begin
    cost_price = FilledAvgPrice;
    if time >= 100500 then begin
        current_profit = Close - cost_price;
        if current_profit < -2000 then begin
            SetPosition(0, label:="接受虧損出場");
        end;
        if current_profit > 2000 then begin
            SetPosition(0, label:="見好就收出場");
        end;
    end;
end;

 

排序方式: 標準 | 最新
石頭 發文於   2024/11/22

少乘1000?

虎科大許教授 發文於   2024/11/22

不論你交易個股或期貨,庫存成本與目前價格差距要超過2000,這個很難。

莊莊 發文於   2024/11/22

對喔...我還沒有把數量算進來...我試試看

XS小編 發文於   2024/11/27

Hello 莊莊,

 

小編補充,您可以參考系統內建的XS交易腳本。

裡面有各種停損停利的寫法。

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