多條件流程

  •   1.4K 
  • 最後發表   VincentHU  2021 九月 03
VincentHU 發文於   2021/08/27

請問要如實現多條件流程呢?

例如:

1.當kd黃金交叉且開盤開在上關價上

2.當kd黃金交叉且開盤開在上關價下/中關價上

3.當kd黃金交叉且開盤開在中關價下/下關價上

4.當kd黃金交叉且開盤開在下關價下

請問要怎麼寫這一個程式呢?

再麻煩小幫手了,謝謝

  • 按讚來自於
  • lobogaw
排序方式: 標準 | 最新
XQ小幫手 發文於   2021/08/31

Hello VincentHU,

 

您只要使用 if else 作邏輯判斷即可。

舉例來說:

input: Length(9), RSVt(3), Kt(3);

variable: rsv(0), k(0), _d(0);

value1 = getfield("Low", "D")[1] + (getfield("High", "D")[1] - getfield("Low", "D")[1]) *1.382;    //上關

value2 = (getfield("High", "D")[1] + getfield("Low", "D")[1]) / 2;    //中關

value3 = getfield("High", "D")[1] - (getfield("High", "D")[1] - getfield("Low", "D")[1]) *1.382;    //下關

Stochastic(Length, RSVt, Kt, rsv, k, _d);

 

condition1 = k cross above _d; //黃金交叉

condition2 = open > value1; //開盤在上關上,如果要用日開盤的話是 getfield("Open", "D") 取代 open

condition3 = open < value1 and open > value2;  //開盤在上關中關間

condition4 = open < value2 and open > value3;  //開盤在中關下關間

condition5 = open < value3; //開盤在下關下

 

if condition1 and condition2 then begin

    //當kd黃金交叉且開盤開在上關價上要做什麼

    end

else if condition1 and condition3 then begin

    //當kd黃金交叉且開盤開在上關價下/中關價上要做什麼

    end

else if condition1 and condition4 then begin

    //當kd黃金交叉且開盤開在中關價下/下關價上要做什麼

    end

else if condition1 and condition5 then begin

    //當kd黃金交叉且開盤開在下關價下要做什麼

    end;

VincentHU 發文於   2021/09/01

謝謝小幫手

那如果想加入警示訊息,例如開在上關價上就顯示開上關價上的訊息,要怎麼寫呢?

我把你提供的寫法修正程式碼後,用retmsg=text("開在上關價上);但是到警示中心看,發現不管有沒有開在上關價上,都只會顯示開上關價上,請問是哪裡出錯呢?

謝謝小幫手

XQ小幫手 發文於   2021/09/03

Hello VincentHU,

 

如果您只有寫 retmsg=text("開在上關價上); 的話,那自然所有的警示訊息都會是 開在上關價上。

您需要編寫不同相對應的警示訊息才行,舉例來說:

if condition1 and condition2 then begin

    //當kd黃金交叉且開盤開在上關價上要做什麼

    ret = 1;

    retmsg=text("開在上關價上);

    end

else if condition1 and condition3 then begin

    //當kd黃金交叉且開盤開在上關價下/中關價上要做什麼

    ret = 1;

    retmsg=text("開在上關價下/中關價上);

    end

else if condition1 and condition4 then begin

    //當kd黃金交叉且開盤開在中關價下/下關價上要做什麼

    ret = 1;

    retmsg=text("開在中關價下/下關價);

    end

else if condition1 and condition5 then begin

    //當kd黃金交叉且開盤開在下關價下要做什麼

    ret = 1;

    retmsg=text("開在下關價下);

    end;

發表回覆
Close