Double condition ( "OR" in MQL4)
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) && ... ) { ... }
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.
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) ) ...
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!
|
|
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.