移動停損+移動固定停利

  •   230 
  • 最後發表   阿杜  2023 一月 10
阿杜 發文於   2023/01/05

請教~ 回測後停在第1次停利,後面2、3次停利腳本沒進續進行,請教原因,謝謝!!

if Position = 0 and short_condition then begin setposition(-10);        { 進場做空 }

end;

 

if Position = -10 and Filled = -10 then begin

{ 空10張 }

 

 

{ 範本移動停損腳本}

var: intrabarpersist stoploss_point(0);

 

if stoploss_point = 0 then begin

stoploss_point = FilledAvgPrice*(1+0.01*loss_percent);

end;

 

if Close < FilledAvgPrice then begin

if Close *(1+0.01*loss_percent) < stoploss_point then begin

stoploss_point = Close *(1+0.01*loss_percent);

end;

end;

 

if Close >= stoploss_point or short_condition2 then begin

SetPosition(0);

stoploss_point = 0;

end 

else begin

//--------------------------------------------------------------------------------------------------------------

 

{ 自編移動固定停利腳本}

var:  plratio(0);

if position <> 0 and filled <> 0 then begin

 

if plratio = 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin  //-1.2%

plratio = 1 ;

SetPosition(-6);

 

end else 

 

if plratio = 1 and profit_percent > 0 and Close <= FilledAvgPrice*(0.99-0.01*profit_percent) then begin //-2.2%

SetPosition(-2);

plratio = 2 ;

end else

 

if  plratio = 2 and profit_percent > 0 and Close <= FilledAvgPrice*(0.98-0.01*profit_percent) then begin //3.2%

SetPosition(0) ;

plratio = 0 ;

 

end;

end;

end;

end;

 

排序方式: 標準 | 最新
XQ小幫手 發文於   2023/01/06

 Hello 阿杜,

 

您的停損停利是放在 if Position = -10 and Filled = -10 的條件裡面。

所以一但有部分出場過,部位庫存不等於 -10 的狀況下就不會繼續執行。

建議您在撰寫腳本的時候可以縮排,撰寫判斷式時會比較容易判別。

阿杜 發文於   2023/01/06

所以我把if Position = -10 and Filled = -10 then begin刪除就行了嗎?

XQ小幫手 發文於   2023/01/10

Hello 阿杜,

 

小幫手會建議您將其修改為 if position < 0 and filled < 0 then begin 會比較好。

關於用position和filled控管交易的說明,您可以參考此篇文章

另外,您也可以在腳本中加上print來檢查運算是否有如您所想的運作。

發表回覆
Close