void OnStart()
{Alert ("Total buy order is ",GetOrderCount(ORDER_TYPE_BUY));
}
int GetOrderCount(long type)
{
ulong order_ticket;
int total=0;
//--- go through all pending orders
for(int i=0;i<PositionsTotal();i++)
{
if((order_ticket=OrderGetTicket(i))>0)
{ //if(magic_number == OrderGetInteger(ORDER_MAGIC))
if(type == OrderGetInteger(ORDER_TYPE)) total++;
}
Alert (i);
}
//---
return(total);
}
When I run this script I always get the total as zero, the counter i alerts up to the number of active orders in the terminal.
Also when I switch to OrdersTotal() instead of PositionsTotal(), it returns zero, that is the counter (i) does not count at all.
How do I get this script to return the total number of buy orders?
Why does OrdersTotal() return zero while PositionsTotal() returns the number of active orders in the terminal?
P.S am running this code on MT5