Declaration of boolean variable with conditions

 

Hello, this boolean always returns false (even when conditions are satisfy).

Do you think I have to use if or is there a proper way to declare such expression ? (I have plenty of boolean).

Thank you,


   bool Condition2=(
      Condition1== true && 
      Indic[2]<Indic[1] && 
      Indic[1]>Indic[0]
      );


With if : (works)

bool Condition2;      
   if (Condition1== true && 
      Indic[2]<Indic[1] && 
      Indic[1]>Indic[0])
      {
      Condition2= true;
      }


(not sure it is the right place to post question like this one.

I really like the www.mql5.com website :)


Vivaldi

 

You can use macro definition to solve the issue, for example:

#define Condition2 (Condition1==true&&Indic[2]<Indic[1]&&Indic[1]>Indic[0])
The drawback is that you can not modify "Condition2" in the code because it's not a variable anymore.
 
Vivaldi:

Hello, this boolean always returns false (even when conditions are satisfy).

Do you think I have to use if or is there a proper way to declare such expression ? (I have plenty of boolean).

Thank you,


With if : (works)


(not sure it is the right place to post question like this one.

I really like the www.mql5.com website :)


Vivaldi

Hi,

Both methods are equivalents. My opinion is you have other problem if results differ.

You can also post your question about programming in Expert Advisors and Automated Trading but there is no problem to post here.

 

angevoyageur:

Both methods are equivalents. My opinion is you have other problem if results differ.


I wasn't sure both method are correct. So ok it is clear now. It must be local and global declaration that makes the difference. In the second case I declare bool as a global variable.

Thank you forex2start for the idea.

Reason: