新手請益,移動停利觸發問題?

  •   629 
  • 最後發表   jeffhsu  2024 九月 24
jeffhsu 發文於   2024/09/23

各位先進 小弟想請教關於移動停利的問題,

用台指期15分K,第一口用固定停利,第二口用移動停利,

固定停利,當達到我設定的獲利點數後,盤中觸發即賣出,但在移動停利方面,我想要隨著最高點的變動,當高點小於最大停利點數+停利回跌點(50點)時觸發交易,

以下是用範例的語法寫成,但實際卻不是我想要的,比如:上漲至高點300後跌回至250點,就停利。請問高手能否幫助小弟,是哪個地方需要修改,感激不盡~

 

if Position = 0 and filled = 0 and long_condition[1] and _barNum <> currentbar then   

setposition(2, MARKET); { 以市價買進 }  

  

if Position = 0 and filled = 0 and long_condition1[1] and _barNum <> currentbar then   

setposition(2, MARKET);     { 以市價買進 }  

 

if Position = 2 and Filled = 2 then begin 

 

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

 

if filled = 2 and position = 2 and (low <= (filledAvgPrice - loss_point)) {停損} 

then  setposition(0,market);  

max_profit_point = 0; 

 

if filled = 2 and position = 2 and (high >= (filledAvgPrice + profit_point)) {停利} 

then setposition(1,market); 

 

_barNum = currentbar; 

end; 

 

if Position = 1 and Filled = 1 then begin 

 

{ 判斷是否要啟動停利 } 

if max_profit_point = 0 and high >= FilledAvgPrice + profit_point then begin 

max_profit_point = high; 

 

end else begin 

end; 

 

if max_profit_point <> 0 then begin  

if high <= max_profit_point - profit_drawback_point then begin 

{ 停利 } 

SetPosition(0); 

max_profit_point = 0; 

end else if high > max_profit_point then begin 

{ 移動最大獲利點 } 

max_profit_point = high;  

end;  

end;  

end; 

排序方式: 標準 | 最新
虎科大許教授 發文於   2024/09/23

//移動停利的部份可撰寫如下:
input: profit_drawback_point(50,"停損點數");
var: profit(0), intraBarPersist max_profit_point(0);
if Position = 1 and Filled = 1 then 
    begin 
        { 判斷是否要啟動停利 } 
        profit = c - FilledAvgPrice;
        if profit > max_profit_point then max_profit_point=profit;
        if profit > 0 then 
            if c <= max_profit_point - profit_drawback_point then 
                begin 
                    { 停利 } 
                    SetPosition(0); 
                    max_profit_point = 0; 
                    profit = 0;
                end;
    end;

jeffhsu 發文於   2024/09/24

謝謝教授,我再試試看。

發表回覆
Close