以下是我的移動停損停利的寫法,但我發現有些問題。
1.停損有些單會大大的超過停損設定點數(非周末留倉)。
2.有避免周末不留倉,但有些時候還是會沒有出場,進而導致跳空大停損的狀況。
想請問是寫法有問題嗎?
input: profit_point1(70, "停利(點)") , profit_point2(130, "停利(點)") ;
input: loss_point(50, "停損(點)");
if loss_point = 0 then raiseruntimeerror("請設定停損(點)");
if Position >= 1 then begin
{ 依照成本價格設定停損/停利 }
var: intrabarpersist stoploss_point(0);
{ 計算停損價格 }
if stoploss_point = 0 then begin
stoploss_point = FilledAvgPrice - loss_point;
end;
{ 如果價格上漲的話, 則往上挪動停損價格. 停損價格只會越來越高 }
if Close > FilledAvgPrice then begin
if Close - loss_point > stoploss_point then begin
stoploss_point = Close - loss_point;
end;
end;
if Close <= stoploss_point then begin
{ 停損 }
SetPosition(0,market);
stoploss_point = 0;
end else begin
if profit_point1 > 0 and Close >= FilledAvgPrice + profit_point1 and Position = 2 and Filled = 2 then begin
{ 兩口單時停利1口 }
SetPosition(1,market);
end else if profit_point2 > 0 and Close >= FilledAvgPrice + profit_point2 and Position = 1 and Filled = 1 then begin
SetPosition(0,market);
stoploss_point = 0;
end else if DayOfWeek(Date) = 6 and currentTime >=044000 then begin {周末不留倉}
setposition(0,market);
stoploss_point = 0;
end;
end;
end;
end;
ex:

1 評論