期貨拉回停利的寫法疑問

  •   177 
  • 最後發表   alexw  2022 九月 22
alexw 發文於   2022/09/15

inputs: 

ProfitTarget(10), // 啟動移動停利%

ProfitDrawdown(25); // 損益拉回%

vars:

IntraBarPersist MaxProfit(0);

if Position <> 0 and Filled <> 0 then MaxProfit  = MaxList(MaxProfit, AbsValue(High - FilledAvgPrice)) else MaxProfit = 0; // 多單

if Position <> 0 and Filled <> 0 then MaxProfit  = MaxList(MaxProfit, AbsValue(Low - FilledAvgPrice)) else MaxProfit = 0; // 空單

if Position <> 0 and Filled <> 0 then begin

if MaxProfit > FilledAvgPrice * ProfitTarget * 0.01 and Close > FilledAvgPrice + (MaxProfit * (100 - ProfitDrawdown) * 0.01) then SetPosition(0); // 多單移動停利

if MaxProfit > FilledAvgPrice * ProfitTarget * 0.01 and Close > FilledAvgPrice - (MaxProfit * (100 - ProfitDrawdown) * 0.01) then SetPosition(0); // 空單移動停利

end;

 

假設19:20的高是14650,20:00跌到14550進場然後開啟程式自動停利,再來21:00漲到14620後開始拉回

 

問一下上述語法的High會是當晚最高的14650,還是開啟程式後的高點14620?

 

如果是前者的話,那該如果改寫成後者?

 

 

 

 

 

 

XQ小幫手 發文於   2022/09/22

Hello alexw,

 

high是當根Bar的High,所以會視您使用的頻率來決定。

如果是日頻率的話,就會是該交易日的高點。

若是1分鐘頻率的話,則是該分鐘的高點。

只要 19:20 和 21:00 是不同Bar,那麼high在這個範例裡最高的就會是就會是後面的高點。

 

關於停損停利的出場法,您可以參考XS編輯器裡的內建腳本。

發表回覆
Close