Counting total Sell orders at a certain distance from a Buy order

 

Hi guys and girls,


I m trying to count how many sell orders i have at a certain distance from a Buy order.

This is the code i got but it gives me wrong results.

Thanks a lot.


double OrderOpenPriceSell;

   
int TotalSellOrders()
  {
   
   int SellOrderCount = 0;
   
   
   for(int i = 0; i <= OrdersTotal(); i = i + 1)
    {
     if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
       if(OrderType() == OP_SELL)
        {
         OrderOpenPriceSell = OrderOpenPrice();
        }
         if(OrderOpenPriceSell > BuyOpenPrice - 4500.00 * Point)
         {
          SellOrderCount = SellOrderCount + 1;
         }
      }
     }
   
    
   return(SellOrderCount);
  }   
 
  1. You are potentially incrementing your count for non-sell orders. Move your test inside the type=sell.
  2. There is no order position OrdersTotal(). Remove the equals.
  3. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect/Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
  4. Use ++X instead of X=X+1.
Reason: