Counting Orders

 

I ma trying to count how many pending BUY/SELL stop orders are at any given point. The code I am trying is below, but at the moment it counts nothing.


Any ideas about what is it going on, or a different way to do it?


Thanks.


int
OpenBuyOrders=0,
OpenSellOrders=0;
 
//Count Pending Stop Orders
   for(int i=0;i<OrdersTotal(); i++ )
   {
      if(OrderSelect(i, SELECT_BY_POS)==true)
         {
         if (OrderType()==OP_BUYLIMIT)
            OpenBuyOrders++;
         if (OrderType()==OP_SELLLIMIT)
            OpenSellOrders++;   
         }
   }
 

lococo wrote >>

I ma trying to count how many pending BUY/SELL stop orders are at any given point. The code I am trying is below, but at the moment it counts nothing.


Any ideas about what is it going on, or a different way to do it?


Thanks.

im trying to do the same thing right now ......

 
//+------------------------------------------------------------------+
//|count pending.mq4 |
//|Desmond Wright aka " Buju" |
//|notes: |
// this EA will count all the pending orders |
// for the chart it has been placed on |
// |
//+------------------------------------------------------------------+
#property copyright "Desmond Wright aka Buju"
#property link ""

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int OpenBuyOrders;
int OpenSellOrders;
int total;

int start()
{
  OpenBuyOrders=0;
  OpenSellOrders=0;
  total=0;

//Count Pending Stop Orders
  for(int i=0; i<OrdersTotal(); i++ )
   {
    if(OrderSelect(i, SELECT_BY_POS)==true)
     {
      if (OrderType()==OP_BUYSTOP)
        OpenBuyOrders++;
      if (OrderType()==OP_SELLSTOP)
        OpenSellOrders++;
     }
    total=OpenBuyOrders + OpenSellOrders;
   }
  Comment ("buy_stop=",OpenBuyOrders," sell_stop=",OpenSellOrders," total=",total);
}
//+------------------------------------------------------------------+
 
// the code was checked in EA as follows : 
 
void OnTick()
  {
Alert(Count_Pending_Stop_Orders());
}

int Count_Pending_Stop_Orders(){
 int OpenBuyOrders=0,OpenSellOrders=0;
   for(int i=0;i<OrdersTotal(); i++ )
   {
      if(OrderSelect(i, SELECT_BY_POS)==true)
         {
         if (OrderType()==OP_BUYSTOP)
            OpenBuyOrders++;

         if (OrderType()==OP_SELLSTOP)
            OpenSellOrders++;  
         }
   }
   return(OpenBuyOrders + OpenSellOrders); 
   }


your mistake was in 



  if (OrderType()==OP_BUYLIMIT)
            OpenBuyOrders++;
         if (OrderType()==OP_SELLLIMIT)
your EA will count limit orders which are not stop orders https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_property_double
 
Mohammed Al Zarii:

Why have you replied to a 13 year old post?

Please don't bring old topics to the top without good reason.

Why have you posted when the correct code had been posted in the post above yours?

Please use the code button (Alt+S) when pasting code.

Reason: