Here is the code fuction which will return the total number of lots which are currently running in open trades :

Parameters: key is magic number, and type is the type of trades .


Code:
double gettotallot(int _key, int type)
{
double _lot=0;
 for(int k=OrdersTotal(); k>=0; k--)
                {  
                  if (OrderSelect(k,SELECT_BY_POS,MODE_TRADES)&& OrderSymbol()==Symbol()&& OrderMagicNumber()==_key && OrderType()==type)
                  _lot+=OrderLots();
                  } 
              return(_lot); 
 }