股票移動停損 %

  •   535 
  • 最後發表   桂桂  2023 三月 02
桂桂 發文於   2023/02/25

小幫手  請問如何將期貨的移動停損改成股票% 方式設定

 

 

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;

 

 

XQ小幫手 發文於   2023/03/02

Hello 桂桂,

 

您的移動停損百分比是用進場時的價格差距嗎?

那麼其實只要把 stoploss_point 的計算方式稍作修改即可。

舉例來說,把相對應的部分作修改:

input: loss_point(3, "停損(%)");   //改為用百分比停損

 

stoploss_point = FilledAvgPrice - loss_point;

改為

stoploss_point = FilledAvgPrice * (1 - (0.01 * loss_point));

 

如果價格往上時也要保持一樣的%差距的話,那麼連同上方的修改,將裡面往上挪動停損價格的部分一併作修改

if Close - loss_point > stoploss_point then begin

    stoploss_point = Close - loss_point;

    end;

改為

if Close * (1 - (0.01 * loss_point)) > stoploss_point then begin

    stoploss_point = Close * (1 - (0.01 * loss_point));

    end;

 

發表回覆
Close