指令FilledRecordCount請教

  •   413 
  • 最後發表   winton  2024 八月 16
winton 發文於   2024/08/04

想以已有部位的上筆成交價格作為計算依據平倉,我的(節錄)指令如下:

  if position>1 and position<=5 and c>FilledRecordPrice(FilledRecordCount-1)+20 and buystop then SetPosition(0, MARKET) 

回測結果:沒有result(如附檔)

如果 c>FilledRecordPrice(FilledRecordCount-1)+20刪掉就有結果.請問我的語法有問題嗎謝謝

附加文件

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

FilledRecordCount、FilledRecordPrice等數據在收盤之後就不存在了,所以無法回測。

  • 按讚來自於
  • wintonchung
winton 發文於   2024/08/04

非常感謝教授在假日裡給我釋疑.接著的問題是我可不可以理解為"上面我的語法無法回測驗證.但是可用在行情進行中"?

虎科大許教授 發文於   2024/08/04

FilledRecordCount、FilledRecordPrice等數據雖然可在盤中抓數據,但抓的庫存僅限於當天建立的庫存,歷史庫存是抓不到的。

XS小編 發文於   2024/08/09

Hello winton,

 

如果您仔細看回測報告,可以注意到 回測執行商品 顯示 1(失敗)。

若點進去的話就可以看到錯誤訊息 (參考附圖)。

 

您遇到的錯誤應該是因為 FilledRecordPrice(FilledRecordCount-1) 這種寫法會導致超出範圍。

舉例來說,您第一次出場時因為曾經發生過一次進場,故 FilledRecordCount 會是1,減1後會等於0故導致錯誤。

FilledRecordPrice 的 index 參數範圍是從1開始。

 

另外雖然即時的狀況下只要策略有中斷 FilledRecordCount 等資訊就會重新開始,但回測中是會持續的。

故在回測中是可以使用相關的交易函數。

您可以將數值用 print 印出確認。

附加文件

winton 發文於   2024/08/16

謝謝.那麼如果想寫:比上筆進場多單的價格+2平倉出場.該怎麼寫?

虎科大許教授 發文於   2024/08/16

if filledRecordCount>1 then value1=FilledRecordPrice(FilledRecordCount-1);

發表回覆
Close