int PositionLastClosedType(string f_symbol="", // instrument finansowy
                           int    f_magic=-1)  // identyfikator
  {
//---
   datetime f_timeClose=0;
   int      f_type=-1;
   for(int i=OrdersHistoryTotal()-1; i>=0; i--)
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
         if((f_symbol==OrderSymbol()      || f_symbol=="") &&
            (f_magic ==OrderMagicNumber() || f_magic==-1))
            if(OrderCloseTime()>f_timeClose)
              {
               f_timeClose=OrderCloseTime();
               f_type=OrderType();
              }
   return f_type;
  }