Total pending orders placed by the EA

 

Hello everyone,

I am trying to count pending orders placed by an EA. There is a very odd result -134545644 or so. This function runs in OnTick() function. Can someone help to get the correct result? I've included the code below. Thanks!

int ordersTotal = OrdersTotal();                // Total Orders
int expertOrders;                               // Variable to store total EA orders
for(int i = 0; i <= ordersTotal - 1; i++){
ulong orderTicket = OrderGetTicket(i);          // Get Order Ticket
OrderSelect(orderTicket);                       // Select ticket
int orderMagic = OrderGetInteger(ORDER_MAGIC); // Get Order Ticket Number
if(orderMagic == EXPERT_MAGIC){
expertOrders++;
}
}
 
Buba Akhrakhadze:

Hello everyone,

I am trying to count pending orders placed by an EA. There is a very odd result -134545644 or so. This function runs in OnTick() function. Can someone help to get the correct result? I've included the code below. Thanks!

You should set expertOrders to zero before you count.

Else it might have anything in it stored.


 
for(int i = 0; i <= ordersTotal - 1; i++){

If there are n orders, their indexes are [0 … n-1].

 
Dominik Christian Egert #:
You should set expertOrders to zero before you count.

Else it might have anything in it stored.


Thanks, It worked.
 
Buba Akhrakhadze #:
Thanks, It worked.
Follow Williams advice as well...


Reason: