請小幫手解惑,為何回測時間有設定但跑回測時卻會在時間前進行交易

  •   105 
  • 最後發表   YH_Kevin  2024 一月 04
YH_Kevin 發文於   2023/12/18

程式如下我設定9:10分後才會進行交易,但在跑回測時卻有一筆是9:05就進行交易的,看Log並無發生這件事情想請問回測運作的邏輯?以及如何驗證跟實盤交易一樣?

Value5 = getfield("high","Tick")[getfield("當日序號", "Tick")-1];
if Position = 0 and close[1] > Value5 then begin if currenttime >= 091000 then print(file("c:\Print_1\[Symbol].log"),"買進日期:",date,"當天開盤最高價=",Value5,"前一根收盤價=",close[1],"當前Bar:",CurrentBar,"當前時間:",currentTime); SetPosition(1, OPEN); { 以市價買進 }



 

 

附加文件

XQ小幫手 發文於   2024/01/04

Hello, YH_Kevin.

小幫手在貼您的CODE的時候,發現您少了一個End;

 

且第二個if 並沒有寫上 Begin & end: 所以 currenttime >= 091000 這邊只有寫LOG

Value5 = getfield("high","Tick")[getfield("當日序號", "Tick")-1];

if 
    Position = 0 
    and close[1] > Value5 
then begin
    if 
        currenttime >= 091000 
    then
        print(file("c:\Print_1\[Symbol].log"),"買進日期:",date,"當天開盤最高價=",Value5,"前一根收盤價=",close[1],"當前Bar:",CurrentBar,"當前時間:",currentTime);
    SetPosition(1, OPEN);       { 以市價買進 }
end;

幫您修改後如下:

Value5 = getfield("high","Tick")[getfield("當日序號", "Tick")-1];

if 
    Position = 0 
    and close[1] > Value5 
then begin
    if 
        currenttime >= 091000 
    then Begin
        print(file("c:\Print_1\[Symbol].log"),"買進日期:",date,"當天開盤最高價=",Value5,"前一根收盤價=",close[1],"當前Bar:",CurrentBar,"當前時間:",currentTime);
        SetPosition(1, OPEN);       { 以市價買進 }
    end;
end;

回測是在9:10後才進場

謝謝。

發表回覆
Close