Efficient way of condition checking suggestion for MQL4/MQL5 executor.

 

While after these years, the mql4/mql5 conditional checking seems still run in an inefficient way, raise a discussion is needed.

Nowadays condition checking in most modern programming language would be:

"And"

if (cond_1 && cond_2 && cond_3) {
  run();
}

Either of the cond_1, cond_2 or cond_3, it will ignore the nested code.

And if cond_1 is FALSE already, the code executor will ignore the cond_2 and cond_3 check and jump to next. 

MQL "And" 

What mql4/mq5 doing is don't ignore the cond_2 and cond_3 check even cond_1 is FALSE already. 

This affects the code performance or need to manual add more condition check layers to guarantee the code performance.

"Or" 

if (cond_1 || cond_2 || cond_3) {
  run();
}

Still, if cond_1 is TRUE, the common case of modern language is ignore the cond_2 and cond_3 check.

 

What I want to say is, do you think the executor should be better adapt to the modern standard than it's current status?

I wait many years of update, still don't see any attempts to do this change.

 
kolier:

While after these years, the mql4/mql5 conditional checking seems still run in an inefficient way, raise a discussion is needed.

Nowadays condition checking in most modern programming language would be:

"And"

Either of the cond_1, cond_2 or cond_3, it will ignore the nested code.

And if cond_1 is FALSE already, the code executor will ignore the cond_2 and cond_3 check and jump to next. 

MQL "And" 

What mql4/mq5 doing is don't ignore the cond_2 and cond_3 check even cond_1 is FALSE already. 

This affects the code performance or need to manual add more condition check layers to guarantee the code performance.

"Or" 

Still, if cond_1 is TRUE, the common case of modern language is ignore the cond_2 and cond_3 check.

 

What I want to say is, do you think the executor should be better adapt to the modern standard than it's current status?

I wait many years of update, still don't see any attempts to do this change.

Are you sure ?

In OR, if any condition is true - not just the first - then the whole condition is true. 

Is always tricky to use if with various condition. I create the script below and found that your statement is incorrect. Can you prove otherwise ?.

void OnStart()
  {
  PlaySound("wait.wav");
  int count, value = 0;
  bool condition [8][3];
  string txt="";
  
  Print("");
  
  // decimal to binary : set various condition  
  for (count = 0; count < 8;count ++)
     {
     value = count;
     if (value - 4 >= 0){value -=4; condition [count][0] = true;} else condition [count][0] = false;
     if (value - 2 >= 0){value -=2; condition [count][1] = true;} else condition [count][1] = false;
     if (value - 1  >= 0)condition [count][2] = true; else condition [count][2] = false;

     Print(""+count+":  Condition is "+ condition [count][0]+ " & "+condition [count][1]+" & "+condition [count] [2]);
     }
  
  Print("");
  Print("Checking various condition for AND.");
  
  for (count = 0; count < 8;count ++)
    {
    txt = "Condition is "+condition [count][0]+" & "+condition [count][1]+" & "+condition [count] [2];
    
    if (condition [count][0] == true && condition [count][1] == true && condition [count][2] == true)
       {
       Print ("",count," AND TRUE : All of condition is true. ",txt);
       }
       else
       {
       Print("",count," AND FALSE : One of condition is false. ",txt);
       }
    }
  
  Print("");
  Print("Checking various condition for OR.");
  
  for (count = 0; count < 8;count ++)
    {
    txt = "Condition is "+condition [count][0]+" | "+condition [count][1]+" | "+condition [count] [2];
    
    if (condition [count][0] == true || condition [count][1] == true || condition [count][2] == true)
       {
       Print ("",count," OR TRUE : One of condition is true. ",txt);
       }
       else
       {
       Print("",count," OR FALSE : All of condition is false. ",txt);
       }
    }
  return;
  }



 
phi.nuts:

Are you sure ?

In OR, if any condition is true - not just the first - then the whole condition is true. 

Is always tricky to use if with various condition. I create the script below and found that your statement is incorrect. Can you prove otherwise ?.

Yes, you are right. The latest MQL5 executor adapts this change now, maybe MQL4 get abandoned.

My most complex things still in MQL4, it's time to transfer to MQL5 now. :D 

A little tricky but useful in many cases together with variable assign in the condition part.

But which is most important is adapts to standard. 

Thanks. 

 
kolier:

Yes, you are right. The latest MQL5 executor adapts this change now, maybe MQL4 get abandoned.

My most complex things still in MQL4, it's time to transfer to MQL5 now. :D 

A little tricky but useful in many cases together with variable assign in the condition part.

But which is most important is adapts to standard. 

Thanks. 

Again, are you sure ? I have MT5 build 730 (Current build is 742), and MT4 build 419, 438, 445 and 451 (Yes I have them all).

And no error found executing that script.

Reason: