小編.教授 您好
可以麻煩幫我看看那邊出錯嗎?目前編輯是沒問題.可是試跑回測.只會跑多單謝謝
{
多空單停損(%)
}
input: profit_percent(1, "停利(%)");
input: loss_percent(1, "停損(%)");
var: long_condition(false); { 進場買進作多 }
var: long_condition1(false); {進場買進做空 }
{
均線穿越時以市價買進1張
以成交價為基礎, 設定固定的停損/停利價格, 觸及時出場
}
long_condition = eMA(Close, 13) cross over eMA(Close, 34);
long_condition1 = eMA(close, 13)cross under eMA(close,34);
if Position = 0 and long_condition then begin
SetPosition(1,market ); { 以市價買進 }
if Position = 0 and long_condition1 then begin
SetPosition(-1, MARKET); { 以市價賣進 }
end;
end;
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);
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;
end;
end;
5 評論