Total Buy lots and Total Sell Lots from mql4 to mql5

 
   How this code would be for MT5?


double totalBuyLots = 0;
      double totalSellLots = 0;
      
      for(int i=0; i < OrdersTotal(); i++)
      {
        
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         {
            // match the symbol EUR/USD or EUR/CHF, etc
            if(OrderSymbol() == Symbol())
            {
               if(OrderType() == OP_BUY)
                  totalBuyLots += OrderLots();
               if(OrderType() == OP_SELL)
                  totalSellLots += OrderLots();
            }
         }    
      }

 
You may start reading here!
 
Carl Schreiber:
You may start reading here!

I have tried to use this sample, but I don't know how to select only buy/sell orders to count them...



void OnStart()
  {
//--- variables for returning values from order properties
   ulong    ticket;
   double   open_price;
   double   initial_volume;
   datetime time_setup;
   string   symbol;
   string   type;
   long     order_magic;
   long     positionID;
//--- number of current pending orders
   uint     total=OrdersTotal();
//--- go through orders in a loop
   for(uint i=0;i<total;i++)
     {
      //--- return order ticket by its position in the list
      if((ticket=OrderGetTicket(i))>0)
        {
         //--- return order properties
         open_price    =OrderGetDouble(ORDER_PRICE_OPEN);
         time_setup    =(datetime)OrderGetInteger(ORDER_TIME_SETUP);
         symbol        =OrderGetString(ORDER_SYMBOL);
         order_magic   =OrderGetInteger(ORDER_MAGIC);
         positionID    =OrderGetInteger(ORDER_POSITION_ID);
         initial_volume=OrderGetDouble(ORDER_VOLUME_INITIAL);
         type          =EnumToString(ENUM_ORDER_TYPE(OrderGetInteger(ORDER_TYPE)));
         //--- prepare and show information about the order
         printf("#ticket %d %s %G %s at %G was set up at %s",
                ticket,                 // order ticket
                type,                   // type
                initial_volume,         // placed volume
                symbol,                 // symbol
                open_price,             // specified open price
                TimeToString(time_setup)// time of order placing
                );
        }
     }
//---
  }

 

    

TRY THIS CODE

double
totalBuyLots = 0;       double totalSellLots = 0;              for(int i=0; i < PositionsTotal(); i++)       {         ulong ticket=PositionGetTicket(i);          if(PositionSelectByTicket(ticket))          {             // match the symbol EUR/USD or EUR/CHF, etc             if(PositionGetString(POSITION_SYMBOL) == Symbol())             {                if( PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)                   totalBuyLots += PositionGetDouble(POSITION_VOLUME);                if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)                   totalSellLots += PositionGetDouble(POSITION_VOLUME);             }          }           }
Reason: