I am just learning to code mql4 and it appears as though there are no "and" "or" operators which are common to almost any programming language. In the mql4 documentation it gives the usual bitwise and logical operators but no "and" "or". Does this mean that all expressions comparing various conditions will have to be a complicated combination of nested if else and switch statements. Is there no way to write an expression such as this in mql4 without using nested if or switch statements: if(((a>b) and (e>b)) or (r>s)) {} ? Thank you for your time
use this && for "and"
|| for "or"
example
if(((a>b) && (e>b)) || (r>s))
{
blah blah blah
}
thanks, ejoi
Use of logical operators
I am trying to write and "if" statement that requires the use of two &&.
for example if ( A>B && C>D && E>F) buy
if (A<B && C<D && E<F) sell
When compilig I get no errors. However, the system seems to hangup and does not do anything. I have tried using a single && and everything works fine. Is there a way to use two or more && in a single "if" statement
Something is definately wrong with your code. There is nothing wrong with those 2 statements.
Try validating each condition individually and see which one stalls, e.g.
if (A>B) Print("1");
if (C>D) Print("2");
if (E>F) Print("3");
If a sequence of 1,2,3 doesn't appear in your Journal, then you'd know which condition fails.
Not the Language
I am trying to write and "if" statement that requires the use of two &&.
for example if ( A>B && C>D && E>F) buy
if (A<B && C<D && E<F) sell
When compilig I get no errors. However, the system seems to hangup and does not do anything. I have tried using a single && and everything works fine. Is there a way to use two or more && in a single "if" statementI have put up to 5 &&s in an If statement and there wasn't any problem. I suppose you could bracket your conditions, but this should only be necessary for || (ors). There is definitely something wrong with your code. Its probably very subtle.
I am trying to write and "if" statement that requires the use of two &&.
for example if ( A>B && C>D && E>F) buy
if (A<B && C<D && E<F) sell
When compilig I get no errors. However, the system seems to hangup and does not do anything. I have tried using a single && and everything works fine. Is there a way to use two or more && in a single "if" statement{
OrderSend(); //Buy
}
if ((A < B) && (C < D) && (E < F))
{
OrderSend(); //Sell
}This will work.
I have a similar problem.
This simple code alway give "true" as result, when must give "false". Any idea about the problem?
Thanks in advace
double a=3; double b=5; bool c=true; bool d=false; if ((a<b)&&(c=true)&&(d=true)) {Alert("TRUE");} else {Alert("FALSE");}
I have a similar problem.
This simple code alway give "true" as result, when must give "false". Any idea about the problem?
Thanks in advace
You re using assignment operator for boolleans not comparison operator
Change that to this
double a=3; double b=5; bool c=true; bool d=false; if ((a<b)&&(c==true)&&(d==true)) {Alert("TRUE");} else {Alert("FALSE");}
and it will work OK
I try used operator && if more time
but doesn't work
Is this correct?
if ((a && b) && (c && d ) && ( e && f)) {Alert("TRUE");} else {Alert("FALSE");}
Thank you
-
“Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
How To Ask Questions The Smart Way. 2004
When asking about codeUse the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
Your code if ((a && b) && (c && d ) && ( e && f))
Simplified if (a && b && c && d && e && f)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am just learning to code mql4 and it appears as though there are no "and" "or" operators which are common to almost any programming language. In the mql4 documentation it gives the usual bitwise and logical operators but no "and" "or". Does this mean that all expressions comparing various conditions will have to be a complicated combination of nested if else and switch statements. Is there no way to write an expression such as this in mql4 without using nested if or switch statements: if(((a>b) and (e>b)) or (r>s)) {} ?
Thank you for your time