小幫手 請問如何將期貨的移動停損改成股票% 方式設定
input: profit_point(10, "停利(點)");
input: loss_point(10, "停損(點)");
if Position = 1 and Filled = 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 profit_point > 0 and Close >= FilledAvgPrice + profit_point then begin
{ 停利 }
SetPosition(0);
stoploss_point = 0;
end else if Close <= stoploss_point then begin
{ 停損 }
SetPosition(0);
stoploss_point = 0;
end;
end;
1 評論