For some strange reason, it seems that the person who wrote the code wants to count all except limit orders.
Keith you are right that Limit Orders are not included in the code sample - I guess my question, which I should have been more to the point in articulating, is that is that OrdersTotal() is a count of all Market and Pending orders.
So it does not count cancelled orders which if true makes MODE_TRADES redundant ?
Keith you are right that Limit Orders are not included in the code sample - I guess my question, which I should have been more to the point in articulating, is that is that OrdersTotal() is a count of all Market and Pending orders.
So it does not count cancelled orders which if true makes MODE_TRADES redundant ?
MODE_TRADES is the default
MODE_HISTORY is the pool for closed and cancelled orders
I'm not sure what you are asking.
MODE_TRADES is the default
MODE_HISTORY is the pool for closed and cancelled orders
I'm not sure what you are asking.
When I output (with Comment) a count of my Market & pending Orders by using the code snippet above (note that I do not use Buy or Sell Limits so that is why the Pendings are Stops only in the code sample) and I compare it to an output of the count using OrdersTotal() they are the same count.
Which has me wanting to not call the function which is the code snippet that I have posted but rather just use a call to OrdersTotal() instead - given that this count gives the same result.
this then has me wonder why anyone wanting a count of their market and Pending orders would cycle thru OrdersTotal() [ie for(i=OrdersTotal()-1;i>=0;i--)] with the filter (OrderCloseTime() == 0) and / or (OrderType() == OP_BUY || OrderType() == OP_SELL || OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP) etc... to gain a count of Market and Pending Orders ?
this then has me wonder why anyone wanting a count of their market and Pending orders would cycle thru OrdersTotal() [ie for(i=OrdersTotal()-1;i>=0;i--)] with the filter (OrderCloseTime() == 0) and / or (OrderType() == OP_BUY || OrderType() == OP_SELL || OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP) etc... to gain a count of Market and Pending Orders ?
I have no idea why anybody would code that either.
Usually you would also check magic number and Symbol so that you are only counting orders placed by the EA.
If you just use the total, any trades placed manually or by another EA would also be included.
I have no idea why anybody would code that either.
Usually you would also check magic number and Symbol so that you are only counting orders placed by the EA.
If you just use the total, any trades placed manually or by another EA would also be included.
- Going through the market orders, OrderCloseTime will always be zero. If it is closed/deleted, it's in the history list. The only things in the list are buy/sell/stops/limits. There are nothing else.
- In history there are. See code comment:Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
- Likely someone copied code that was looking at history, and changed the pool, but nothing else.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I see this code offered to those wanting a count of their Open and Pending orders
int num-0;
for(i=OrdersTotal()-1;i>=0;i--)
{
if ((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) && ((OrderCloseTime() == 0) &&
(OrderType() == OP_BUY || OrderType() == OP_SELL || OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP))) num++;
}
return (num);
But is not the result of this exercise the same as OrdersTotal() ? Making the MODE_TRADES redundant ?