How to Get The Lowest Open Lot

 

Hello. I have a program that opens a position with a higher lot size if there's a position open and it aims to multiply based on the lowest lot size but I'm having trouble getting the lowest lotsize. Please help

double getLowestLots(){

   double lowestLots = 0;
   for(int i = 0; i < PositionsTotal(); i++){
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket)){
         if(PositionGetInteger(POSITION_MAGIC) == InpMagicNumber){
            lowestLots = PositionGetDouble(POSITION_VOLUME);;
         }
      } 
   }
   return lowestLots;
}
 

I did not compile or test this:

double getLowestLots(){

   double lowestLots = 0;
   for(int i = 0; i < PositionsTotal(); i++){
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket)){
         if(PositionGetInteger(POSITION_MAGIC) == InpMagicNumber){
            if(lowestLots == 0) lowestLots = PositionGetDouble(POSITION_VOLUME);
            else lowestLots = MathMin(lowestLots, PositionGetDouble(POSITION_VOLUME));
         }
      } 
   }
   return lowestLots;
}
 

there's a function from the CSymbolInfo library

#include <Trade/Trade.mqh>
#include <Trade/SymbolInfo.mqh>

CTrade trade;
CSymbolInfo m_symbol;   
    
    if (!m_symbol.Name(Symbol()) || !m_symbol.Refresh()){
    
      Print("Failed to select or refresh symbol information for ", Symbol());

    }   

double lotSizeMin = m_symbol.LotsMin();