移動停利相關問題

  •   239 
  • 最後發表   王小光  2023 十二月 07
王小光 發文於   2023/12/05

input:profit_point(50,"停利%");

input:profit_drawback_point(3,"停利回跌%");

input:loss_point(3,"停損%");

 

if position>0 and filled>0 then begin

//移動停利條件

if profit_point = 0 then raiseruntimeerror("請設定停利%");

if profit_drawback_point = 0 then raiseruntimeerror("請設定停利回跌%");

if profit_drawback_point > profit_point then raiseruntimeerror("停利需大於停利回跌");

var: intrabarpersist max_profit_point(0); { 啟動停利後最大獲利點 }

 

{ 停損 }

if loss_point > 0 and Close<FilledAvgPrice*(1-(0.01*loss_point)) then begin

SetPosition(0,market);

max_profit_point = 0;

end;

 

{ 判斷是否要啟動停利 }

if max_profit_point = 0 and close>=FilledAvgPrice then begin

max_profit_point = close;

end;

 

{ 停利 }

if max_profit_point <> 0 then begin

if Close <= max_profit_point*(1-(0.01*profit_drawback_point)) then begin

SetPosition(0,market);

max_profit_point = 0;

end;

 

{ 移動最大獲利點 }

if Close>max_profit_point then begin

max_profit_point = Close;

end;

 

end;

end;

 

以上是我參考內建的移動停利腳本修改成%數腳本

我的進場跟出場分成兩個腳本,使用模擬帳號測試出場腳本時似乎沒有觸發出場;使用交易回測是有歷史進出場

想請問小幫手幾個問題

1.每天開盤前啟動策略是否會有影響

2.內建腳本有用到 if...then begin....end else begin...end,我是將每一段敘述分開寫是否也是同樣的效果?

3.日頻率跟分鐘頻率在價格判斷上有執行上的差異嗎?

XQ小幫手 發文於   2023/12/07

 Hello 王小光,

 

小幫手建議您先閱覽網站的教學區,裡面有XS語法的基礎和應用。

 

1.

小幫手不知道您完整腳本是如何,回測設定如何,不過需注意每個策略啟動後都是獨立的,A策略買進並不會對B策略的庫存造成影響。

因此當您將進場和出場分成兩個策略時,兩者自然不會互動。

除非出場策略設定為依庫存,且等到進場策略進場後才啟動,這樣出場策略才抓的到A策略買進的庫存。

 

2.不太一樣。

if 條件1 then begin 動作1 end else if 條件2 then begin 動作2 end else begin 動作3 end 

只會執行3個動作中的其中一個,就算條件1和條件2都相同。

 

if 條件1 then begin 動作1 end

if 條件2 then begin 動作2 end

這種寫法只要條件符合就會動作,故條件1條件2同時符合的話,就會執行動作1和動作2。

 

這些條件判斷邏輯是所有語言都相同的,如果看不懂XQ的說明也可以看其他程式語言的教學。

 

3.如果您只用close那麼沒有差別,因為最新的成交價都會相同。

但是其他資料大多有差,像open就會分別是當日的開盤價跟該分鐘的開盤價。

發表回覆
Close