condition問題

  •   247 
  • 最後發表   阿林  2022 十月 20
阿林 發文於   2022/10/19

請問小幫手 我下列語法哪裡有問題 因為我有用print 找到明明條件不一樣 但condition6的print顯示TRUE

所以有些條件跟我寫的condition6不一樣 卻觸發 再麻煩小幫手幫我檢查了

condition6 = high <> GetField("最高價", "D") and close <= close[1]*0.995 and close[1] > high[1]*0.995 and 

close[2] > high[2]*0.995 and high[1] = GetField("最高價", "D") or high[2] = GetField("最高價", "D");

 

因為我也寫滿多condition的 只有condition6 裡面有用到or 其他都沒用到or 所以是不是在想說or的問題

 

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

 Hello 阿林,

 

小幫手改寫一下,你或許會比較好理解。

原本的寫法就和以下相同:

condition1 = high <> GetField("最高價", "D") and close <= close[1]*0.995 and close[1] > high[1]*0.995 and close[2] > high[2]*0.995 and high[1] = GetField("最高價", "D");

condition2 = high[2] = GetField("最高價", "D");

condition6 = condition1 or condition2;

所以只要 condiiton1 或 condition2 其中一個成立,condition6 就會成立。

 

您想要的應該是這樣才對:

condition6 = high <> GetField("最高價", "D") and close <= close[1]*0.995 and close[1] > high[1]*0.995 and close[2] > high[2]*0.995 and (high[1] = GetField("最高價", "D") or high[2] = GetField("最高價", "D"));

 

阿林 發文於   2022/10/20

感謝小幫手解答

請問小幫手

condition1 = high <> GetField("最高價", "D") and close <= close[1]*0.995 and close[1] > high[1]*0.995 and close[2] > high[2]*0.995 and high[1] = GetField("最高價", "D");

condition2 = high[2] = GetField("最高價", "D");

condition6 = condition1 or condition2;

所以只要 condiiton1 或 condition2 其中一個成立,condition6 就會成立

以上這邊小幫手改的我看得懂意思

 

 

condition6 = high <> GetField("最高價", "D") and close <= close[1]*0.995 and close[1] > high[1]*0.995 and close[2] > high[2]*0.995 and (high[1] = GetField("最高價", "D") or high[2] = GetField("最高價", "D"));

這邊跟我原本的語法只是差在於加了個() 

所以請問小幫手 這兩個是都能用嗎 還是只有上面的能用呢 再麻煩小幫手了

XQ小幫手 發文於   2022/10/20

 Hello 阿林,

 

兩者都可用,但出來的結果會不同,上面的會跟您原本寫的有相同結果。

簡單說明:

condition1 = 條件1 and 條件2 or 條件3;

這樣的寫法只要 條件1 和 條件2 符合,或是條件3符合,condition1 就會成立。

 

condition1 = 條件1 and (條件2 or 條件3);

這樣的寫法只要 條件1 和 條件2 符合,或是 條件1 和 條件3 符合,condition1 才會成立。

 

您可以自行選擇所需的使用。

發表回覆
Close