Is there "from : to" function ?

 

I wonder if there is a function enable me to shorten this conditions:


if(High[i] >  High[1+i]

&&  High[i] >  High[2+i]

&&  High[i] >  High[3+i]

&&  High[i] >  High[4+i]

&&  High[i] >  High[5+i]

&&  High[i] >  High[6+i]

&&  High[i] >  High[7+i]

&&  High[i] >  High[8+i]

&&  High[i] >  High[9+i]

&&  High[i] >  High[10+i]

&&  High[i] >  High[11+i]

&&  High[i] >  High[12+i]

)


To become for example:

if(High[i] >  (High[1+i] : High[12+i] )


@William Roeder "Please say something useful or be silent" :)

 

Just get the highest value of that array range and verify that it is in fact at index [i] (use function ArrayMaximum).

For other situations, you can use a "for" loop to build up your boolean condition.

 
Fernando Carreiro:

Just get the highest value of that array range and verify that it is in fact at index [i] (use function ArrayMaximum).

For other situations, you can use a "for" loop to build up your boolean condition.

Thanks Mr. Fernando , but what if the code is :

if(Close[i] >  Close [1+i]

&&  Close [i] >  Close [2+i]

&&  Close [i] >  Close [3+i]

&&  Close [i] >  Close [4+i]

&&  Close [i] >  Close [5+i]

&&  Close [i] >  Close [6+i]

&&  Close [i] >  Close [7+i]

&&  Close [i] >  Close [8+i]

&&  Close [i] >  Close [9+i]

&&  Close [i] >  Close [10+i]

&&  Close [i] >  Close [11+i]

&&  Close [i] >  Close [12+i]

)


How can i use a "for" loop to build up my boolean condition?

 
Ahmed Abd El Aziz: Thanks Mr. Fernando , but what if the code is :How can i use a "for" loop to build up my boolean condition?

As an example of an "and (&&)" loop, here is sample code (compiled but untested):

bool boolHighest = true;
for( int j = i + 1; j <= i + 12; j++ ) boolHighest = boolHighest && ( Close[ i ] > Close[ j ] );
if( boolHighest ) { /* your code for the valid condition */ };
 
Fernando Carreiro #:

As an example of an "and (&&)" loop, here is sample code (compiled but untested):

Thank you. It is working.

 
Ahmed Abd El Aziz #: but what if the code is :
if(Close[i] >  Close [1+i]
&&  Close [i] >  Close [2+i]
&&  Close [i] >  Close [3+i]
&&  Close [i] >  Close [4+i]
&&  Close [i] >  Close [5+i]
&&  Close [i] >  Close [6+i]
&&  Close [i] >  Close [7+i]
&&  Close [i] >  Close [8+i]
&&  Close [i] >  Close [9+i]
&&  Close [i] >  Close [10+i]
&&  Close [i] >  Close [11+i]
&&  Close [i] >  Close [12+i]
)

How can i use a "for" loop to build up my boolean condition?

  1. Please edit your two posts and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. MT5 has no predefined High[]/Close[]. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  3. No loop is required for that.
    if(Close[i] >  Close [ ArrayMaximum(Close, i+1, 12) ])
    Or simplified.
    if(i == ArrayMaximum(Close, i, 13))