Download MetaTrader 5
To add comments, please log in or register
Interested in MQL5 features? Find them in documentation!
Alexandru Ionut Comanoiu
515
Alexandru Ionut Comanoiu 2016.03.20 13:48 

Hi!

I need someone with a bigger and smarter brain.

How can i do something like this:

Add conditions in an "if" only if another condition is true.

//------------------------------------------------------------------------------

if (condition1 && condition2 &&

                if (condition3==true) {condition4 && condition5} &&

                if (condition6==true) {condition7 && condition8)

  )

//------------------------------------------------------------------------------

Hope someone knows this or i'll have to write hundreds line of code.

Mohammad Soubra
23404
Mohammad Soubra 2016.03.20 14:22  
Alexandru Ionut Comanoiu:

Hi!

I need someone with a bigger and smarter brain.

How can i do something like this:

Add conditions in an "if" only if another condition is true.

//------------------------------------------------------------------------------

if (condition1 && condition2 &&

                if (condition3==true) {condition4 && condition5} &&

                if (condition6==true) {condition7 && condition8)

  )

//------------------------------------------------------------------------------

Hope someone knows this or i'll have to write hundreds line of code.

if (condition1 && condition2)
{
    if (condition3==true)
    {
        if (condition4 && condition5)
        {
            if (condition6==true)
            {
                if (condition7 && condition8)
                {
                    .............................................................;
                    .............................;
                    ...............;
                }
            }
        }
    }
}

Alexandru Ionut Comanoiu
515
Alexandru Ionut Comanoiu 2016.03.20 16:34  
Mohammad Soubra:

Thanks for the reply, but i think i was'nt too clear. The first "if" should do something if the conditions are ok. But, if the other conditions are true the result should be different. In your example all the conditions have to be met.

To be more specific, the first two conditions in the first "if" are mandatory and the other ones are aplied filters. I don't know wich filter is aplied so i need to check the filters and add conditions to the first "if", only if the filters are active.

Mohammad Soubra
23404
Mohammad Soubra 2016.03.20 18:42  
Alexandru Ionut Comanoiu:

Thanks for the reply, but i think i was'nt too clear. The first "if" should do something if the conditions are ok. But, if the other conditions are true the result should be different. In your example all the conditions have to be met.

To be more specific, the first two conditions in the first "if" are mandatory and the other ones are aplied filters. I don't know wich filter is aplied so i need to check the filters and add conditions to the first "if", only if the filters are active.

clarify please

Vasyl Nosal
18465
Vasyl Nosal 2016.03.20 18:49  

I do not know what you want but maybe else will help you.

else
Mohammad Soubra
23404
Mohammad Soubra 2016.03.20 21:02  
can you post the real code????
Khurram Mustafa
26145
Khurram Mustafa 2016.03.20 21:17  

you can move if condition every where 

just like true false

if 1 && 2 met result else false result

other ways

if 1 && 2 not met = answer if answer is not met return 

Khurram Mustafa
26145
Khurram Mustafa 2016.03.20 21:18  
Further more, please show limited code
Alexandru Ionut Comanoiu
515
Alexandru Ionut Comanoiu 2016.03.21 01:58  

I've done it!

(condition3 and condition6 are extern bool vars)

//--------------------------------------------------------

bool condition4 =true;

bool condition5 =true;

bool condition7 =true;

if (condition3==true)  { condition4 = blah blah.... ;

                                     condition5 = whathev......;}

if (condition6==true)     condition7 = fsdasfwerefdsf;

//--------------------------------------------------------------------------------------

if (condition1 && condition2      && condition4 && condition5  && condition7)

{

do something.....

}

//--------------------------------------------------------------------------------------

if... let's say some filters (condition3 and condition6) are false 4,5,7 are true so they does'nt alter the result. If the filters are true, 4,5,7 are taken in consideration in the if.

Anyway, thanks everyone!

Khurram Mustafa
26145
Khurram Mustafa 2016.03.21 12:24  
you are welcome
/
To add comments, please log in or register