Need an function "GetTotalLots()"

 

Hello, Is there anyone help me to write a function "GetTotalLots()" function? no matter "buy" or "sell", just want them sum together.


Thank you for your help.

 

Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help (2017)

MT4: Learn to code it.
MT5: Begin learning to code it.

If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

 

Try this:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   PrintFormat("Total volume of open positions: %.2f",GetTotalLots());
  }
//+------------------------------------------------------------------+
//| Get volume of all open positions                                 |
//+------------------------------------------------------------------+
double GetTotalLots()
  {
   double volume_total=0;
   int    positions_total=PositionsTotal();
   for(int i=0; i<positions_total; i++)
     {
      PositionGetSymbol(i);
      volume_total+=PositionGetDouble(POSITION_VOLUME);
     }
   return(volume_total);
  }
//+------------------------------------------------------------------+