For loop help

 

Hello friends,

I'm new to MQL and fairly new to MQL5 community so I really hope I'm asking this question at the right place. I intend to upgrade this simple 3 bar entry criteria with a for loop so that I can give an extern variable later on how many bars to look for.


Original code:

if(Open[1] < Close[1] && Open[2] < Close[2] && Open[3] < Close[3])
         {
            Print("entryOutput=1");
         }

The idea I had:

 for(i = 1; i <= 3; i++)
 {
        if(Open[i] < Close[i])
        {
         Print("entryOutput=1");
        }
 }

However it keeps printing without meeting the intended 3 bar closing above the open condition. 

Could you please give me a hint on how to nest if and for loops together?

Thanks,

M

 
That is because you are acting on just one condition. Your original was all three.
bool condition=true;
 for(i = 1; i <= 3; i++) if(Open[i] > Close[i]) condition=false; // One or more are not less than.

if(condition) {                                                  // All three are less than.
         Print("entryOutput=1");
        }
 
William Roeder:
That is because you are acting on just one condition. Your original was all three.
I see. Make sense. Thank you William! Have a good day.