Hello, 小幫手好
用下面的程式碼做回測(放空),停損利2%,回測出來的出場時間有點怪,
正確來說,應該是價格在成本價上面的停損點跟出場時間是正確的
但是價格低於成本價的停利點,常都是拖比較久才出場
以下圖為例,9.22空單進場價格為26.5,明明10/3號應該就碰到停利點了,但卻拖到10/4號才出場,請小幫手協助了解下問題在哪,謝謝


input:maxprice(100,"最高價格");
input:minV(500,"最小成交量");
//開盤低於昨天收盤
condition1=getfield("開盤價","D")<=GetField("參考價","D");
//進場
if
condition1
and close<=maxprice
and getfield("volume","D")[1]>minV
and GetSymbolInfo("買賣現沖") = true
then setposition(-1);
//出場
input: profit_percent(2, "停利(%)");
input: loss_percent(2, "停損(%)");
if Position = -1 and Filled = -1 then begin
{ 依照成本價格設定停損/停利: 請注意當作空時, 判斷是否獲利的方向要改變 }
if profit_percent > 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin
{ 停利 }
SetPosition(0);
end else if loss_percent > 0 and Close >= FilledAvgPrice*(1+0.01*loss_percent) then begin
{ 停損 }
SetPosition(0);
end;
end;
1 評論