我的策略為什麼執行回測都無法作用

  •   75 
  • 最後發表   Wade韋  2022 一月 13
Wade韋 發文於   2022/01/10

input: magic_number(2,"魔術點數");

input: profit_percent(1.5,"停利(%)");

input: loss_percent(1.5,"停損(%)");

input:last_time(123000,"最後進場時間");

input:exit_time(130000,"離場時間");

var:money(200);

var:intraBarPersist entry_price(0);

 

var: maV_60(0),point_buy(0);

maV_60 = average(volume[2],60);

 

if point_buy <= 60 then point_buy = point_buy + 1;

 

 

if 

position = 0 

and filled = 0 

and point_buy = 60

and volume[1] > maV_60 * magic_number

and close[1] > open[1]

and currentTime <= last_time  

then

Begin

  setposition(money/close);

  entry_price = close;

End;

 

 

 

if  position > 0 and filled > 0 

and (

close >= entry_price * (1+0.01*profit_percent)

or  close <  entry_price * (1-0.01*loss_percent)

or  currentTime >= exit_time

)

then 

begin

  setposition(0,market);

end;

 

XQ小幫手 發文於   2022/01/13

Hello Wade韋,

 

因為您的腳本在資料讀取筆數時也會運算。

所以 point_buy 會在您資料讀取筆數時就上到 61 導致沒有交易。

您可以實際 print 出來觀察即可得知。

若不希望在資料讀取筆數時也運算的話,可以使用 getinfo 裡的 trademode 來判斷。

發表回覆
Close