Download MetaTrader 5
To add comments, please log in or register
Do you have Linux? Find out how to install MetaTrader on it!
Pavel Soukup
559
Pavel Soukup 2015.02.04 10:14 

Information to all

 

Hi guys,

I deal with now time optimalization mql code. I have found that preprocesor mql language test all boolean conditions even though the result is clear already after some condition.

Example: When 5 conditions type boolean and your code is:

if  ( cond1 & cond2 & cond3 & cond4 & cond5 ) ...

   if cond1 is false -> is clearly that result all conditions is false so. But MQL preprocesor testing all conditions. If "cond.." is example function with return boolean type, can it calcul operation inside this function more time - unnecessarily!

Demonstrativ code:

 My question - Does have mql preprocesor some direktive for it? I would like write code as if  ( cond1 & cond2 & cond3 & cond4 & cond5 ) ... and at the same time I need time optimalization code.

Thank you. 

#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  { // version time optimization
    bool cond1=false;
    uint timer=GetTickCount();
    if ( cond1)
      if(Cond2()) {}
    Alert("Version quickly: Working time is: ",GetTickCount()-timer,"ms");
   
   // version time slowly
    cond1=false;
    timer=GetTickCount();
    if ( cond1& Cond2()) {}
    Alert("Version slowly: Working time is: ",GetTickCount()-timer,"ms");
   

  }
//+------------------------------------------------------------------+
bool Cond2()
{ int i=0;
  while (i<10002220)
  { 
    i++;
  }
  return (false);
}
Ovo Cz
2958
Ovo Cz 2015.02.04 10:31  
endy5:

 

Information to all

 

Hi guys,

I deal with now time optimalization mql code. I have found that preprocesor mql language test all boolean conditions even though the result is clear already after some condition.

Example: When 5 conditions type boolean and your code is:

if  ( cond1 & cond2 & cond3 & cond4 & cond5 ) ...

   if cond1 is false -> is clearly that result all conditions is false so. But MQL preprocesor testing all conditions. If "cond.." is example function with return boolean type, can it calcul operation inside this function more time - unnecessarily!

Demonstrativ code:

 My question - Does have mql preprocesor some direktive for it? I would like write code as if  ( cond1 & cond2 & cond3 & cond4 & cond5 ) ... and at the same time I need time optimalization code.

Thank you. 

What do you mean by the "preprocessor test all boolean conditions" ? Anyway, during runtime the processing follows the C++ standards for 600+ code (with strict directive).

Pavel Soukup
559
Pavel Soukup 2015.02.04 12:47  

If I have conditions: 1.) false 2.)true 3.) true 4.) true and 5.) true

and code if ( cond1 && cond2 && cond3 && cond4 && cond5 )  {...}

process running and testing all conditions although result is clearly after test the first condition.

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2015.02.04 13:18  
Have you tried it at normal charts? The condition you are saying should stop immediately if cond1 is false.
whroeder1
13599
whroeder1 2015.02.04 14:08  
endy5:

 if  ( cond1 & cond2 & cond3 & cond4 & cond5 ) ...

   if cond1 is false -> is clearly that result all conditions is false so. But MQL preprocesor testing all conditions. If "cond.." is example function with return boolean type, can it calcul operation inside this function more time - unnecessarily!

Is necessary. It has to compute all five because you are computing a bit mask. 1 & 2 & 4 == 0 Bitwise Operations - MQL4 Documentation

Use boolean operators cond1 && cond2 && cond3... Boolean Operations - MQL4 Documentation

the calculation of the expression is terminated when the result of the expression can be precisely estimated.
Pavel Soukup
559
Pavel Soukup 2015.02.04 21:45  

Hi WHRoeder,

 I have no doubt that you know more about mql than I do... but my time test code does not endorse what you write:

"the calculation of the expression is terminated when the result of the expression can be precisely estimated."

 

For my basic time test code on top page - quickly version time test is 0ms, slowly version about 10ms. I repeted test many times. It is fact.

whroeder1
13599
whroeder1 2015.02.04 22:11  
What I wrote and what you initially wrote are different. Show the actual code.
peter.MT4Web
158
peter.MT4Web 2015.02.04 22:22  

Hi endy5!

You can`t compare your 2 versions.

If you are computing a BIT MASK, you can't split the Operation into two ore more lines. If you do so, you'll get a different result.


I think you will do a LOGICAL Operation (your variables are bool and initalized with false). Therfore you have to use && as Boolean Operator.

Pavel Soukup
559
Pavel Soukup 2015.02.05 07:18  

Hi.

I am sorry. Very stupid my inattention!  You have the right!

Perhaps it would be better to delete the whole thread, because it is just wrong. Does not have any information for others users.

I am sorry.  

/
To add comments, please log in or register