How Can I Get Total Lot Size for my Buy positions?

 
double Lotsize()
      {
      double BuyLots=0;
       for (int i=PositionsTotal()-1;i>=0;i--)
            {
           
            if (PositionSelect(PositionGetSymbol(i)==_Symbol))
            if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
               {BuyLots+=PositionGetDouble(POSITION_VOLUME);}}
       return BuyLots;}

I coded this function to get the total lot size for my buy positions but it gives 0.00 all the time. Can I get assistance please

 
sir7williams:

I coded this function to get the total lot size for my buy positions but it gives 0.00 all the time. Can I get assistance please

double totalBuyVolume(int Magic)  
{
double result = 0;
  
   ulong order_ticket; 
   int total=0; 
   for(int i=0;i<PositionsTotal();i++) 
   {
      if((order_ticket=PositionGetTicket(i))>0) 
         if(PositionGetInteger(POSITION_MAGIC)==Magic && 
         PositionGetString(POSITION_SYMBOL)==_Symbol && 
         PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) result+=PositionGetDouble(POSITION_VOLUME);
   } 
   
return(result); 
}
 
Thank U Sir, You provide a complete solution!!
 
Nikolay Georgiev:
Thank you so much sir