Download MetaTrader 5

Declaration of boolean variable with conditions

To add comments, please log in or register
Vivaldi
40
Vivaldi 2013.08.16 15:04 

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

Jian Chen
Moderator
3647
Jian Chen 2013.08.16 15:57  

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.
Alain Verleyen
Moderator
31134
Alain Verleyen 2013.08.16 17:21  
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.

Vivaldi
40
Vivaldi 2013.08.16 17:35  

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.

To add comments, please log in or register