請問符合條件輸出結果語法

  •   105 
  • 最後發表   JingGang  2022 四月 06
JingGang 發文於   2022/03/23

XQ小幫手你好, 

請問一下, 若想要篩選符合多個條件, 可以用下列語法?

condition7 = condition2 and condition3 and condition4;

condition8 = condition5 and condition6;

if condition1 or condition7 or condition8 then ret=1 ;

排序方式: 標準 | 最新
XQ小幫手 發文於   2022/03/28

Hello JingGang,

 

可以,您這就等同於如下語法。

if condition1 or (condition2 and condition3 and condition4) or (condition5 and condition6) then ret = 1;

JingGang 發文於   2022/03/28

你好,

不知道為什麼, 我用OR的語法, 但是輸出只有 condition8 ?

可以幫我檢查一下為什麼嗎?

謝謝

 

condition1 = GetField("Volume", "D") > GetField("Volume", "D")[1] and GetField("Volume", "D")[1] < average(GetField("Volume", "D")[1], 5) and close > high[1];

condition2 = trueall(getfield("Volume", "D")[1] < getfield("Volume", "D")[2], 5);  

condition3 = getfield("Volume", "D") > lowest(getfield("Volume", "D"), 6);  

condition4 = close > getfield("high", "D")[lowestbar(getfield("Volume", "D"), 6)];  

 

value1 = average(volume, 5);  

value2 = truecount(volume < value1, 5);  

value3 = lowestbar(volume, value2);  

 

condition5 = value3 <> 0;  

condition6 = high[value3] < close;  

 

condition7 = condition2 and condition3 and condition4;

condition8 = condition5 and condition6;

 

if condition1 or condition7 or condition8 then ret=1 ;

XQ小幫手 發文於   2022/04/06

Hello JingGang,

 

您可以使用print來看condition的執行狀況。

小幫手這邊測試 condition1, condition7, condition8 都各自有True 的狀況發生。(參考附圖)

不知道您所說的輸出只有condition8是發生在什麼狀況下?

另外需注意使用時有可能會發生超過索引值的狀況,所以小幫手有作特別處理,避免取到負索引值。

附加文件

發表回覆
Close