Search code examples
for-loopmql4

boolean function for loop mql4


I would like to write a reiterated if condition

if (BOX_H1(1) && BOX_H1(2) && BOX_H1(3) && BOX_H1(4) && BOX_H1(5) && BOX_H1(6) && BOX_H1(7) && BOX_H1(8);)

In a for loop form, something like this:

if (
for (int x=1;x<=7; x++)
          {
               (BOX_H1(x));

          })

where BOX_H1(1) si a boolean functions that takes int (shift parameter), but this code doesen't works.

Anyone knows how can i write it out?

EDIT: My code is in this form:

bool Buy_H1 =0, ...

...

if(Buy_H1) {if(...)}

...

void Entry() 
{
Buy_H1 =BOX_H1(1) && BOX_H1(2) && BOX_H1(3) && BOX_H1(4) && 
        BOX_H1(5) && BOX_H1(6) && BOX_H1(7) && BOX_H1(8) ;
}

If, instead of the last code, I substitute

void Entry() 
{
bool Buy_H1(const int parameter){
for(int i=1; i<=parameter; i++){
  if(!BOX_H1(i))
     return false; }
return true; }
}

I reach 'Buy_H1' - function can be declared only in the global scope


Solution

  • bool booleanFunction( const int parameter ){
         for( int i = 1; i <= parameter; i++ ){
              if ( !BOX_H1( i ) )
                   return false;
         }
         return true;
    }
    
    
    void OnStart(){
         ...
         if (  booleanFunction( 8 ) ){
               Print( "OK" );
         }                                   //edited, your code instead of this
         ...
    }