請問移動停損可以把多空寫在一起嗎?

  •   377 
  • 最後發表   菜菜  2025 四月 08
菜菜 發文於   2025/03/25

請問移動停損可以把多空寫在一起嗎?謝謝

排序方式: 標準 | 最新
虎科大許教授 發文於   2025/03/25

若你寫成交易腳本的話,是可以的。

菜菜 發文於   2025/03/28

請教老師,開啟洗價會不會累計上一筆的

虎科大許教授 發文於   2025/03/28

(1)開啟洗價指的是開啟「逐筆」洗價?

(2)不懂你所謂的累計上一筆指的是什麼。

菜菜 發文於   2025/03/31

(1)開啟洗價指的是開啟「逐筆」洗價?

--> 是的

(2)不懂你所謂的累計上一筆指的是什麼。

-->如果使用逐筆,需要加 intrabarpersist  這個嗎 

 

爬文爬到這一篇

https://forum.xq.com.tw/thread/%E9%97%9C%E6%96%BC%E9%80%90%E7%AD%86%E4%BA%A4%E6%98%93/

 

虎科大許教授 發文於   2025/03/31

逐筆洗價的情況下,若變數的數值要保留給下一個Tick,必須加intrabarpersist。

菜菜 發文於   2025/03/31

請教老師~我該怎麼改,謝謝

 

input: profit_point(100, "停利(點)");

input: loss_point(100, "停損(點)");

 

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,MARKET,label:="多單停利");

stoploss_point = 0;

end else if Close <= stoploss_point then begin

{ 停損 }

SetPosition(0,MARKET,label:="多單停損");

stoploss_point = 0;

end;

end;

 

 

input: profit_point2(100, "停利(點)");

input: loss_point2(100, "停損(點)");

 

 

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

{ 依照成本價格設定停損/停利 }

var: intrabarpersist stoploss_point2(0);

 

{ 計算停損價格 }

if stoploss_point2 = 0 then begin

stoploss_point2 = FilledAvgPrice + loss_point2;

end;

 

{ 如果價格下跌的話, 則往下挪動停損價格. 停損價格只會越來越低 }

if Close < FilledAvgPrice then begin

if Close + loss_point2 < stoploss_point2 then begin

stoploss_point2 = Close + loss_point2;

end;

end;

 

if profit_point2 > 0 and Close <= FilledAvgPrice - profit_point2 then begin

{ 停利 }

SetPosition(0,MARKET,label:="空單停利");

stoploss_point2 = 0;

end else if Close >= stoploss_point2 then begin

{ 停損 }

SetPosition(0,MARKET,label:="空單停利");

stoploss_point2 = 0;

end;

 

end;

 

虎科大許教授 發文於   2025/04/01

你的stoploss_point及stoploss_point2分別用來代表多頭及空頭的移動停利價位,只要是獲利狀態,判斷close與它們的關係,以決定是否停利。在多頭部位情況下,出場用if Close <= FilledAvgPrice - stoploss_point判斷停損是錯誤的,應該改成if Close <= stoploss_point or Close <= FilledAvgPrice - loss_point同時判斷移動停利出場及停損出場

 

菜菜 發文於   2025/04/01

謝謝老師,我在試試。確實常常發生剛進場就停損或停利出場,找不出哪裡有問題

XS小編 發文於   2025/04/08

 Hello 菜菜,

 

小編補充,您可以參考 intrabarpersist 語法的說明。

會比較容易理解何時適合使用此語法作宣告。

發表回覆
Close