# Double condition ( "OR" in MQL4)

479

Hello to all. I need help to find out if the code I wrote is right or not.
I wrote this code to mean that the condition is valid if I cross the RSI at level 50.
```.....

if(iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i) < 50
&& iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i+1) > 50
&&............```

I would like to add an additional condition which is valid if the RSI cross the level 50 "OR" if the RSI is below the 10 level.

I wrote this code but I would like to know from the experts if it is correct:

```.....

if((iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i) < 50 + iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i+1) > 50 || iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i) < 10)
&&............```

Thank you all, Massimo.

Moderator
33502

omissamf:
Hello to all. I need help to find out if the code I wrote is right or not.
I wrote this code to mean that the condition is valid if I cross the RSI at level 50.

I would like to add an additional condition which is valid if the RSI cross the level 50 "OR" if the RSI is below the 10 level.

I wrote this code but I would like to know from the experts if it is correct:

Thank you all, Massimo.

It's not correct. You need to use && and parentheses :

```double current    = iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i);
double previous   = iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i+1);

if(((current<50 && previous>50) || current<10)
&& ...
)
{
...
}
```
479

Thanks, angevoyageur.

But I could also write:

```.....

if((iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i) < 50 && iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i+1) > 50 || iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i) < 10)
&&............

```

or is it really wrong?

Massimo.

7364

Let it become your habit if you mix && and || always use parentheses!

in your case you open 2 '(' and don't close them but - what do you want (?):

a)  iRSI(1) && ( iRSI(2) || iRSI(3) ) && iRSI(4) ...   or

b)  (iRSI(1) && iRSI(2) ) || ( iRSI(3) && iRSI(4) ) ...

Moderator
33502

omissamf:
Thanks, angevoyageur.

But I could also write:

or is it really wrong?

Massimo.

 gooly: Let it become your habit if you mix && and || always use parentheses! Always use parentheses when mixing ands and ors. Or make your code readable. ```double current    = iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i); double previous   = iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i+1); bool wasAbove = previous > 50; bool  isAbove =  current > 50; bool hasCrossed = isAbove != wasAbove; if(hasCrossed){ ... }```