I found somewhere there that i way to optimize the code is to use multiple if() instead of &&. So I made changes in my code and stopped working properly. So where is the bug? Plz help
This worked slowly but properly
And this is "optimized" version
I found somewhere there that i way to optimize the code is to use multiple if() instead of &&.
Sometimes, it can be, but not always and it is is difficult to quantify. I believe it is really up to personal preference and readability of the code.
My personal preference is to split it for more readability's sake and sometimes for speed, but not always.
Stick to what you feel more comfortable with but also consider how readable your code will be (for others or yourself in the future).
Sometimes, it can be, but not always and it is is difficult to quantify. ...
I was understanding "optimize", in the sense of performance, so faster code. In this sense there is no point to use "if()" instead of "&&".
Actually, depending on the situation, using "if()" can sometimes result in faster code, but it is not a set rule, just as there are cases, where the "&&" will be faster. It depends on several factors and is very specific and hard to quantify as I stated. It all boils down to how the compiler refactors the code and translates it into the final "compiled" format.
That is why, I suggested the the OP just stick to what he feels comfortable with or to at least consider readability as a more important factor (than speed) when deciding on which one to use!
As stated by WHRoeder above, and as we are talking about mql4/5, I repeat for the third time
there is no point to use "if()" instead of "&&".
"Shortened conditions check is now used in logical operations, unlike the old MQL4 version where all expressions have been calculated and the check has been performed afterwards."
Tell me if my understanding is good.
if(type == OP_SELL
&& OrderSymbol()==Symbol() && OrderMagicNumber() == MAGICMA && zigzag0> zigzag2 && zigzag0>zigzag1 && zigzag1<zigzag2 && Close<zigzag2&& OrderProfit()>0&& SLforBuy > OrderOpenPrice()
&& -zigzag1+zigzag0> ATRd*0.5
Currently if one of the conditions above is not fulfilled the program will not check the next condition? e.g. OrderMagicNumber() != MAGICMA , so zigzag0> zigzag2 and next conditions will not be checked because whole expression is not true.