你好:
我編寫XS交易程序,設定期數並設停損利(%)用來回測我的選股策略,結困成交次數大幅減少,好像時間沒到就被賣出
我的程序碼如下,請惠予協助改正謝謝.
input:ordersize_w(25, "每筆交易金額(萬)");
input:profit_percent(25,"停利(%)");
input:loss_percent(10,"停損(%)");
input:hold_days(60,"持有天數");
var: order_price(0); { 預期委託價格 }
var: order_qty(0); { 換算後數量 }
var: Limit_days(0); { 期限 }
order_price = AddSpread(Close, 1);
order_qty = floor((ordersize_w * 10000) / (order_price * 1000));
if Position = 0
and position = filled
then begin
SetPosition(order_qty+position,market);
Limit_days=dateAdd(currentDate,"d",hold_days);
end else
if Position > 0
and position = filled
then begin
if profit_percent > 0 and Close >= FilledAvgPrice*(1+0.01*profit_percent) then begin
{ 停利 }
setposition(0, market);
return;
end
else if loss_percent > 0 and Close <= FilledAvgPrice*(1-0.01*loss_percent) then begin
{ 停損 }
setposition(0, market);
return;
end
else if Limit_days<>0 and currentDate >= Limit_days then begin
{ 到達持有期數 }
setposition(0, market);
return;
end;
end;
11 評論