Logical expressions

 
Hello all,

I'm curious about how MQL interprets logical expressions. If you check the code bellow you will see two "equivalent" expressions, but one is a normal expression, were I compare each element individually, on the second expression it looks like that MQL allows to compare all elements at once! Is this correct? In some tests I made both expressions return 1 or 0 when appropriate, so they look like to act the same way. If this type of logical expressions can safely be used than it will help to simplify some of my logical expressions. Anyone can confirm this?

int start() { double Teeth = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, 0); // First Type of expression Alert(High[5] > Teeth && Close[4] > Teeth && Close[3] > Teeth && Close[2] > Teeth && High[1] > Teeth); // Second Type expression Alert((High[5] && Close[4] && Close[3] && Close[2] && High[1]) > Teeth); return(0); }


Thank you. Regards,
Cleon
 
Hi again,

Ok I noticed that it doesn't work correctly, anyway can anyone try to explain what are we comparing using the second expression? We have 5 values using a logical operator and. From what I understand, all 5 values inside the ( ) have a value different from 0 so they are interpreted as true, so the expression will be first interpret as (true && true && true && true && true) > Teeth which results in 1 > Teeth, if the condition is true than the result is 1 else is 0, and this way it explains why some results appear at first glance to be correct.

Ok, this doesn't make much sense because it's bad programming, but I wanted to understand (even if wrong), the result given by both expressions. Thank you.

Cleon