How to count number of pending order opened in MT5

 

Hello, 

I want to count the open pending order. But my code cannot count correctly, can anyone give me a help? Thanks

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);
}
 
int ChecklimitedOrders16(int MagicNr)

What is the meaning of this number?

 
no menaing, just a function name for me easy to look. the whole function name i create is "ChecklimitedOrders16"
 
To Pui Kuen:
no menaing, just a function name for me easy to look. the whole function name i create is "ChecklimitedOrders16"
Could you show all of your code? It needs to be put into context for a proper solution.
 
lippmaje:
Could you show all of your code? It needs to be put into context for a proper solution.

above is all my code.

i want to count the open pending limit order. But the counting is wrong.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of...
 

add something like this:



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 )
      {
        ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);
        if(type==ORDER_TYPE_BUY_LIMIT || type==ORDER_TYPE_SELL_LIMIT)
        TodayslimitedOrders ++;
      }
   }
   return(TodayslimitedOrders);
}
 
Arkadii Zagorulko:

add something like this:

Thanks... But still not correct.

If no pending order, it say "0"

if 1 pending order open, it also say"0"

if 2 pending order open, it say"1"


the counting number is missing 1

 
To Pui Kuen:

Thanks... But still not correct.

If no pending order, it say "0"

if 1 pending order open, it also say"0"

if 2 pending order open, it say"1"


the counting number is missing 1

I thought you couldn't find how to count only limit oredrs, your initial function  counts all pending's. 

And last function only limit orders, perhaps you put stop orders and expecting  that function will count this orders.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of...
 
Arkadii Zagorulko:

I thought you couldn't find how to count only limit oredrs, your initial function  counts all pending's. 

And last function only limit orders, perhaps you put stop orders and expecting  that function will count this orders.

But my code counting the order is not correct, keep missing "1" 

do you know how to fix it?

 
      string OrderSymbol = OrderGetString(ORDER_SYMBOL);
      int Magic = OrderGetInteger(ORDER_MAGIC);
      
      OrderSelect(OrderGetTicket(i));
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.

 
To Pui Kuen:

But my code counting the order is not correct, keep missing "1" 

do you know how to fix it?

For first, just take the example from faq.

//--- variables for returning values from order properties 
   ulong    ticket; 
   double   open_price; 
   double   initial_volume; 
   datetime time_setup; 
   string   symbol; 
   string   type; 
   long     order_magic; 
   long     positionID; 
//--- number of current pending orders 
   uint     total=OrdersTotal(); 
//--- go through orders in a loop 
   for(uint i=0;i<total;i++) 
     { 
      //--- return order ticket by its position in the list 
      if((ticket=OrderGetTicket(i))>0) 
        { 
         //--- return order properties 
         open_price    =OrderGetDouble(ORDER_PRICE_OPEN); 
         time_setup    =(datetime)OrderGetInteger(ORDER_TIME_SETUP); 
         symbol        =OrderGetString(ORDER_SYMBOL); 
         order_magic   =OrderGetInteger(ORDER_MAGIC); 
         positionID    =OrderGetInteger(ORDER_POSITION_ID); 
         initial_volume=OrderGetDouble(ORDER_VOLUME_INITIAL); 
         type          =EnumToString(ENUM_ORDER_TYPE(OrderGetInteger(ORDER_TYPE))); 
         //--- prepare and show information about the order 
         printf("#ticket %d %s %G %s at %G was set up at %s", 
                ticket,                 // order ticket 
                type,                   // type 
                initial_volume,         // placed volume 
                symbol,                 // symbol 
                open_price,             // specified open price 
                TimeToString(time_setup)// time of order placing 
                ); 
        } 
     }

and put inside what do you need.

for what do you put the:

OrderSelect()

 if 

OrderGetTicket()

already make what we need.

Reason: