空單回測無法回補

  •   78 
  • 最後發表   StockS  2023 三月 30
StockS 發文於   2023/03/29

你好小幫手

想請問下面的語法,為什麼3-4%空單進場,使用日資料回測,價格到漲停都沒有回補的交易?

謝謝

 

var: intraBarPersist _stop(false);
var: lastdate (0);
value1 = (c - closeD(1) )/ closeD(1);
if lastdate <> date then begin
    lastdate = date ;
    _stop = false;
end;



condition1 =  GetSymbolInfo("買賣現沖") and getField("成交量")[1] > 1000 ;


IF time < 115900 and condition1 = true and _stop = false and value1 > 0.03 and  value1 < 0.04 then begin 
    setposition(-1, market) ;
    _stop = true;
end;

if position < 0 and c >= getfield("漲停價", "D") * 0.99 and _stop = true
then begin
    setposition(0,market);
end;

XQ小幫手 發文於   2023/03/30

 Hello StockS,

 

您的 lastdate 並沒有用 intrabarpersist 宣告,所以 lastdate <> date 這邊會在每次執行都符合條件,故 _stop 會一直被改回 false。(日頻率要當根Bar結束時lastdate才會變為該天日期)

可以將其改為 intrabarpersist ,但須注意這樣若進場當天價格沒有上漲到出場條件的話,隔天 _stop 會被重置為 false ,直到進場條件再度達成時才會改為 true。

發表回覆
Close