請問台指期停損停利寫法

  •   828 
  • 最後發表   維克的投資煩惱  2022 八月 03
維克的投資煩惱 發文於   2022/07/25

有看到標準停損或移動停利的程式碼 但想請問停損停利是否能自己設定範圍跟回檔點數

例如 原設定停損50點 但若逐筆洗價觸到離成本價已賺20點 停損則拉至30 然後又觸到賺40點 停損則只設5點

停利也是若賺40點 回檔20點停利 下一個檻拉到賺90點 回檔30點停利 接著120點 回檔40點停利

即我想要更有彈性去設置停損停利的門檻 而不是固定間距 然後只要觸價到下一門檻就掛價 但又不會跟原本掛的衝突(即取消原本的掛價) 請問能夠做到嗎?

XQ小幫手 發文於   2022/08/03

Hello 維克的投資煩惱,

 

您只需要將內建的停利停損腳本中的回檔點改為變數讓其可以在腳本中變化,而不是input設定即可。

簡單舉移動停利當作範例:

input: _start(40);

var: intrabarpersist max_profit_point(0), intrabarpersist profit_point(20);  //最大獲利點 和 停利距離

 

condition1 = 進場條件;

if position = 0 and filled = 0 and condition1 then setposition(1, market);

 

if position = 1 and filled = 1 then begin

    if max_profit_point = 0 and close >= (filledavgprice + _start) then max_profit_point = close;

    if max_profit_point <> 0 then begin

        if (close - filledavgprice) >= 90 then profit_point = 30 else if (close - filledavgprice) >= 120 then profit_point = 40;   //隨著獲利不同,停利距離變更

        if close <= (max_profit_point - profit_point) then begin

            setposition(0, market);   //停利

            max_profit_point = 0;    //重置最大獲利點

            profit_point = 20;    //重置停利距離

            end

        else if close > max_profit_point then begin

            max_profit_point = close;   //移動最大獲利點

            end;

        end;

    end;

 

另外,停利可以預掛單但停損不行,且setposition一次只能下出一個交易指令。

如果有新的交易指令,而舊的委託單還未成交,舊的將被取消。

細節您可以參考setposition的說明。

發表回覆
Close