Download MetaTrader 5

Counting open orders at a paricular price level

To add comments, please log in or register
itzmyself
17
itzmyself  

I am trying to get a total count of buy (open buy + buylimit + buystop) and sell (open sell + selllimit + sellstop) orders at a particular price level.

The following function code seems to get the count correctly in some instances but shows a zero count in other cases. I am not able to figure out what is causing the issue!

int OpenBuyOrders(double Level)
   {
      int buyorders=0;
      int buylimit=0;
      int buystop=0;
      int totalbuy=0;
      for (int i=0; i<OrdersTotal(); i++)
      {
         if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         if(OrderOpenPrice() == Level)
         {
            if(OrderType() == OP_BUY) buyorders++;
            if(OrderType() == OP_BUYLIMIT) buylimit++;
            if(OrderType() == OP_BUYSTOP) buystop++; 
         } 
         totalbuy= buyorders+buylimit+buystop;
      } 
   return(totalbuy);
   }

int OpenSellOrders(double Level)
   {
      int sellorders=0;
      int selllimit=0;
      int sellstop=0;
      int totalsell=0;
      for (int i=0; i<OrdersTotal(); i++)
      {
         if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         if(OrderOpenPrice() == Level)
         {
            if(OrderType() == OP_SELL) sellorders++;
            if(OrderType() == OP_SELLLIMIT) selllimit++;
            if(OrderType() == OP_SELLSTOP) sellstop++;
         }
         totalsell = sellorders+selllimit+sellstop;
      } 
   return(totalsell);
   }

Ernst Van Der Merwe
4803
Ernst Van Der Merwe  
int OpenSellOrders(double Level)
   {
      int sellorders=0;
      int selllimit=0;
      int sellstop=0;
      int totalsell=0;
      NormalizeDouble(Level,_Digits-1);
      for (int i=0; i<OrdersTotal(); i++)
      { 
         if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         if(NormalizeDouble(OrderOpenPrice(),_Digits-1) == Level)
         {
            if(OrderType() == OP_SELL) sellorders++;
            if(OrderType() == OP_SELLLIMIT) selllimit++;
            if(OrderType() == OP_SELLSTOP) sellstop++; 
         }
         totalsell = sellorders+selllimit+sellstop; 
      }  
   return(totalsell); 
   }
itzmyself
17
itzmyself  
pipPod:
Thanks a ton pipPod!!! I've been banging my head over this for past two days... this is finally working for me now!!!
Ernst Van Der Merwe
4803
Ernst Van Der Merwe  
itzmyself:
Thanks a ton pipPod!!! I've been banging my head over this for past two days... this is finally working for me now!!!
You're welcome.
To add comments, please log in or register