突破特定K棒關鍵價位,如未突破價格,要如何終止條件

  •   186 
  • 最後發表   KKuramas  2023 十一月 29
KKuramas 發文於   2023/11/26

親愛的小編好,

要寫一段突破MACD背離關鍵K棒價位的策略,希望寫收盤價突破關鍵K棒的高點買進,低於關鍵K棒的低點時就放棄動作,寫了以下的條件執行後,卻發現如果跌破關鍵K棒低點後並沒有取消條件,而是等價格回到原關鍵K棒高點後又動作。

請問取消條件的指定要如何寫呢??

value6 = xfMin_MACD("30",xfMin_weightedclose("30"),12,26,9,value1,value2,value3); 

condition1 = value3 crosses over value3[1];

condition2 = close  < close[1];

 

variable: HBprice(0),LBprice(0); 

 

if (condition1 and condition2 ) = true then begin

HBprice =High ; 

LBprice =Low; 

end;

if close crosses over HBprice and close > close[1] then  setposition(1)

else if close crosses under LBprice and close < LBprice then  return; 

XQ小幫手 發文於   2023/11/29

 Hello KKuramas,

 

您可以在突破高點和跌破低點時將變數歸0,或是另外設變數當條件,讓其不再執行。

舉例來說:

var: intrabarpersist _cond(0);

if close crosses over HBprice and close > close[1] and _cond = 0 then setposition(1);

else if close crosses under LBprice and close < LBprice then begin 

    _cond = 1;

    return; 

    end;

 

這樣只要跌破關鍵K棒低點後 _cond 就會等於1,故不會交易。

發表回覆
Close