How to count duplicate price at order limit?

 

Hello, i have problem with my ea.

I have more order limit at level price. But EA creat many  order with duplication price.

I want count order price at level. And I will  filter order  duplication.

How to fix?

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++)
      { 
         long OrderType = OrderGetInteger(ORDER_TYPE);
         if (OrderSelect(OrderGetTicket(i)))
         if(ORDER_PRICE_OPEN == Level)
         {
            if(OrderType == ORDER_TYPE_SELL) sellorders++;
            if(OrderType == ORDER_TYPE_SELL_LIMIT) selllimit++;
            if(OrderType == ORDER_TYPE_SELL_STOP) sellstop++; 
         }
         totalsell = sellorders+selllimit+sellstop; 
      }  
   Print(sellorders,"price",totalsell); 
   return(totalsell); 
   }


 
thuandx89:
if(ORDER_PRICE_OPEN == Level)
string sym=OrderGetString(ORDER_SYMBOL);
double points = SymbolInfoDouble(sym, SYMBOL_POINT);
if(MathAbs(OrderGetDouble(ORDER_PRICE_OPEN) - Level)<points)
 
Yashar Seyyedin #:
string sym=OrderGetString(ORDER_SYMBOL); double points = SymbolInfoDouble(sym, SYMBOL_POINT); if(MathAbs(OrderGetDouble(ORDER_PRICE_OPEN) - Level)<points)
I replaced my code with yours. But I checked OpenSellOrders(131,120) =0
In fact, there are many order with price.
 
thuandx89:
      NormalizeDouble(Level,_Digits-1);

How can you be sure that the order digits are same as current chart digits?

thuandx89:
      NormalizeDouble(Level,_Digits-1);

NormalizeDouble does not work with pass by reference. It returns the result:

      Level = NormalizeDouble(Level, ...);

thuandx89:
if(ORDER_PRICE_OPEN == Level)

This is not how you access order open price. You do it like this:

         OrderGetDouble(ORDER_PRICE_OPEN);
thuandx89:
if(ORDER_PRICE_OPEN == Level)

You cannot compare two doubles. It does not work this way. Check IEEE 754 document.

 

I already fix. Can you check for me?

int CountLevel(double price)
{
   int count = 0;
   for(int i= OrdersTotal() - 1; i >= 0 ; i--)
     {
      double price = OrderGetDouble(ORDER_PRICE_OPEN);
      if(OrderSelect(OrderGetTicket(i)))
        {
         if(price == OrderGetDouble(ORDER_PRICE_OPEN))
          count++;              
        }
     }

 return count;
 }
 
int CountLevel(double price)
{
   int count = 0;
   for(int i= OrdersTotal() - 1; i >= 0 ; i--)
     {
      ulong ticket = OrderGetTicket(i);
      double _price = OrderGetDouble(ORDER_PRICE_OPEN);
      string sym=OrderGetString(ORDER_SYMBOL);
      double points=SymbolInfoDouble(sym, SYMBOL_POINT);
      string diff=MathAbs(price-_price);
      if(diff<points)
          count++;              
     }

 return count;
 }

I did not test and compile.

Note that OrderGetTicket selects the order. No need to invoke OrderSelect again. Also doubles should not be compared that way. Check IEEE 754.

 
Yashar Seyyedin #:

I did not test and compile.

Note that OrderGetTicket selects the order. No need to invoke OrderSelect again. Also doubles should not be compared that way. Check IEEE 754.

Thank you all, I already fix error.