The "if" Syntax Without Any Statement Inside

 
Hello friends, I am new member and not sure if this topic has been discussed before. I recently studying some other people's coding, and went across this part:
void f0_0() {
   if (iClose(Symbol(), PERIOD_H1, 0) > iClose(Symbol(), PERIOD_H1, 2)) {
      if (iClose(Symbol(), PERIOD_H1, 0) < iClose(Symbol(), PERIOD_H1, 2)) {
         if (iClose(Symbol(), PERIOD_H1, 0) > iClose(Symbol(), PERIOD_H1, 1)) {
            if (iClose(Symbol(), PERIOD_H1, 0) < iClose(Symbol(), PERIOD_H1, 1)) {
               if (iOpen(Symbol(), 0, 0) > iOpen(Symbol(), 0, 1)) {
                  if (iOpen(Symbol(), 0, 0) < iOpen(Symbol(), 0, 1)) {
                     if (iClose(Symbol(), 0, 0) > iClose(Symbol(), 0, 1)) {
                        if (iClose(Symbol(), 0, 0) >= iClose(Symbol(), 0, 1)) {
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

I know that the "if" conditions are comparing between close prices & open prices between bars, but why inside the "if" conditions, there are no statements at all? What is the result of this code actually?

 
the purpose is nothing. look at the first and second ifs, they are totally opposite means it wont ether enter the first one or the second one. third and 4th are that way too and rest of them so on.
if this is the hole function you have copied i guess its an spaghetti code or something to make the code kind of messy and un-understandable.
 
void f0_0()

Function names like that look like decompiled code.

 
maronline:
Hello friends, I am new member and not sure if this topic has been discussed before. I recently studying some other people's coding, and went across this part:

I know that the "if" conditions are comparing between close prices & open prices between bars, but why inside the "if" conditions, there are no statements at all? What is the result of this code actually?

That's a really good question and this code suggests that it was written by a novice programmer. You never want to use nesting levels in place of logical and (&&). This is how it should look. 

void function() {
   if (iClose(Symbol(), PERIOD_H1, 0) > iClose(Symbol(), PERIOD_H1, 2) &&
       iClose(Symbol(), PERIOD_H1, 0) < iClose(Symbol(), PERIOD_H1, 2) &&
       iClose(Symbol(), PERIOD_H1, 0) > iClose(Symbol(), PERIOD_H1, 1) &&
       iClose(Symbol(), PERIOD_H1, 0) < iClose(Symbol(), PERIOD_H1, 1) &&
       iOpen(Symbol(), 0, 0) > iOpen(Symbol(), 0, 1) &&
       iOpen(Symbol(), 0, 0) < iOpen(Symbol(), 0, 1)) &&
       iClose(Symbol(), 0, 0) > iClose(Symbol(), 0, 1) &&
       iClose(Symbol(), 0, 0) >= iClose(Symbol(), 0, 1)
   ){
      //do work
   }
}

Then you have the issue of multiple function calls with the same args. If you're calling a function more than once with the same args you need to assign its value to a variable. 


Finally, we get to the worst part of the code. This logic can never resolve to true because the close of the current bar can never be simultaneously greater than AND less than the close of another bar. This might as well have been written as

if (false) {

}
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
HAMED DANESH:
the purpose is nothing. look at the first and second ifs, they are totally opposite means it wont ether enter the first one or the second one. third and 4th are that way too and rest of them so on.
if this is the hole function you have copied i guess its an spaghetti code or something to make the code kind of messy and un-understandable.
Thank you for your reply. Seems you got a good point there. I think the original coder purposely code the spaghetti code to make it difficult to understand as it is a part of code, taken from an EA, so to protect the EA from being copied or manipulated. What I heard was previously there is no way to make our coding in the format of ex4, only mq4, so no way to hide the codes previously. Not sure if its true though.
 
nicholish en:

That's a really good question and this code suggests that it was written by a novice programmer. You never want to use nesting levels in place of logical and (&&). This is how it should look. 

Then you have the issue of multiple function calls with the same args. If you're calling a function more than once with the same args you need to assign its value to a variable. 


Finally, we get to the worst part of the code. This logic can never resolve to true because the close of the current bar can never be simultaneously greater than AND less than the close of another bar. This might as well have been written as

Thank you for your reply. Very good notes for me to learn more on mql4 coding. I conclude that the original writer of the code purposely code the spaghetti code, so to confuse or also can say to protect his/her codes from being manipulated. The code snippet is actually from an EA.
 
William Roeder:

Function names like that look like decompiled code.

Thank you for your reply. In the full coding, there are lots of function names like that. I thought he/she, the original coder, used like a EA coder program or some tools like that to generate the codes.