int PositionLastOpenedType(string f_symbol="", // instrument finansowy
                           int    f_magic=-1)  // identyfikator
  {
//---
   datetime f_timeOpen=0;
   int      f_type=-1;
   for(int i=OrdersTotal()-1; i>=0; i--)
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if((f_symbol==OrderSymbol()      || f_symbol=="") &&
            (f_magic ==OrderMagicNumber() || f_magic==-1))
            if(OrderOpenTime()>f_timeOpen)
              {
               f_timeOpen=OrderOpenTime();
               f_type=OrderType();
              }
   return f_type;
  }