Boolean Function that checks for an open order - page 2

 
WHRoeder:
  1. 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.

  2. Always test return codes
  3. Always count down. Doesn't matter in this case, but its better to get in to the habit.
  4. 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.
 
MisterDog:
For example, "{ # define OP_ALL -1".
if (GetOpenOrderCount() == 0) Print("No open orders");    // Any open orders?
if (GetOpenOrderCount(OP_ALL) >0) Print("some are open"); // Same thing better documented
if (GetOpenOrderCount(OP_BUY) >0) Print("some Buy orders are open");
 
MisterDog:

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 ;) ).

Reason: