int PositionTicketByLot(string f_symbol="",  // instrument finansowy
                        int    f_cmd=-1,     // typ pozycji
                        int    f_magic=-1,   // identyfikator
                        double f_lotMin=0,   // dolna granica wolumenu
                        double f_lotMax=0)   // górna granica wolumenu
  {
   int f_ticket=-1;
//---
   double f_min=MathMin(NormalizeDouble(f_lotMin,2),
                        NormalizeDouble(f_lotMax,2));
   double f_max=MathMax(NormalizeDouble(f_lotMin,2),
                        NormalizeDouble(f_lotMax,2));
//---
   for(int i=OrdersTotal()-1; i>=0; i--)
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         int f_type=OrderType();
         if(f_type==OP_BUYLIMIT || f_type==OP_SELLLIMIT ||
            f_type==OP_BUYSTOP  || f_type==OP_SELLSTOP)
            continue;
         //---
         if((f_symbol==OrderSymbol() || f_symbol=="") && 
            (f_cmd==OrderType()      || f_cmd==-1)    && 
            (f_magic==OrderMagicNumber()                || f_magic==-1) &&
            ((f_min<=OrderLots() && OrderLots()<=f_max) || (f_lotMin==0 && f_lotMax==0)))
            return OrderTicket();
        }
   return f_ticket;
  }