How to count number of pending order opened in MT5 - page 2

 
William Roeder:
What symbol and magic do you expect to read when you haven't yet selected an order?

Perhaps you should read the manual.
   How To Ask Questions The Smart Way. 2004
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

Thank you your advice! Finally i fix my problem.

I only move the 

OrderSelect()

before the symbol and magic code.

Thank you very much

 
Arkadii Zagorulko:

For first, just take the example from faq.

and put inside what do you need.

for what do you put the:

 if 

already make what we need.

Thank you for your help!

I fix the problem finally

 
Arkadii Zagorulko #:

add something like this:

Since you did not post the working code. Will my code work. Please


int CountPendingOrders(ENUM_ORDER_TYPE pendingType) {
   int count = 0;

   for(int i=0; i<OrdersTotal(); i++) {
      
      OrderSelect(OrderGetTicket(i));
      
      string OrderSymbol = OrderGetString(ORDER_SYMBOL);
      int Magic = OrderGetInteger(ORDER_MAGIC);
      ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);
      
      if(Magic == MagicNumber && OrderSymbol == Symbol() && pendingType == type) {
        count++;
      }
   }
   return(count);
}
 
Raphael Adetunji Olaiyapo #:

Since you did not post the working code. Will my code work. Please


Yes thats how its done 

 
To Pui Kuen:
int ChecklimitedOrders16(int MagicNr) {    int TodayslimitedOrders = 0;    for(int i=0; i<OrdersTotal(); i++)    {       string OrderSymbol = OrderGetString(ORDER_SYMBOL);       int Magic = OrderGetInteger(ORDER_MAGIC);              OrderSelect(OrderGetTicket(i));       if(OrderSymbol == Symbol())       if(Magic == MagicNr )       {          TodayslimitedOrders += 1;       }    }    return(TodayslimitedOrders); }

      for(int i=PositionsTotal()-1;i>=0;i--)   Your count had a small issue

Reason: