A more general, more usable function would be
Makes the test explicit: ==0, ==1, or >0 (many) Avoids double negative logic. Allows specific order types.
Always count down. Doesn't matter in this case, but its better to get in to the habit.
You wouldn't ever say if( (2+2 == 4) == true) would you? The ==true is redundant. So is the if(OrderSelect(...) == true)
I really enjoy this point in programming, when you can remove lines of code and the program gets better! This is written something like a zen koan (that's a compliment). As a beginner, it will take some time to unpack all this. For example, "{ # define OP_ALL -1". I'm sure I'll be working on that all afternoon. -- thanks.
if (GetOpenOrderCount() == 0) Print("No open orders"); // Any open orders?if (GetOpenOrderCount(OP_ALL) >0) Print("some are open"); // Same thing better documentedif (GetOpenOrderCount(OP_BUY) >0) Print("some Buy orders are open");
And RaptorUK points out the benefits of paying attention to return values in a great post listed above. And he points out that the function may be doing a little more than I expected as it also checks for Pending Orders.
Yep !
Please MisterDog, pay attention to the correct way of writing OrderSelect(). See my example and WHRoeder's, not DeVries's (Sorry about that deVries ;) ).
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I really enjoy this point in programming, when you can remove lines of code and the program gets better! This is written something like a zen koan (that's a compliment). As a beginner, it will take some time to unpack all this. For example, "{ # define OP_ALL -1". I'm sure I'll be working on that all afternoon. -- thanks.
For example, "{ # define OP_ALL -1".
So here's what I'm taking away from this exercise:
Writing code in double negative is not incorrect (little joke) it just makes things harder to understand.
The rewrites done by deVries and onewithzachy remove the double negative.
And RaptorUK points out the benefits of paying attention to return values in a great post listed above. And he points out that the function may be doing a little more than I expected as it also checks for Pending Orders.
Yep !
Please MisterDog, pay attention to the correct way of writing OrderSelect(). See my example and WHRoeder's, not DeVries's (Sorry about that deVries ;) ).