I need help to Get Last Open Trade Ticket for a specific type and Open price of that ticket

 
I am new in MQL5. I am struggling with writing a function to get last open trade ticket for a specific type and Open price of that ticket. Appreciate any help. 
// Function to get the ticket of the last trade of a specific type
ulong LastTradeTicket(ENUM_ORDER_TYPE orderType)
  {
   ulong lastTicket = 0;
   datetime lastEntryTime = 0;
   for(int i = 0; i < PositionsTotal(); i++)
     {
      if(PositionSelect(i))
        {
         if(PositionGetInteger(POSITION_TYPE) == orderType && PositionGetInteger(POSITION_MAGIC) == MagicNumber)
           {
            ulong currentTicket = PositionGetTicket(i);
            datetime currentEntryTime = PositionGetInteger(POSITION_TIME);

            if(lastEntryTime == 0 || currentEntryTime > lastEntryTime)
              {
               lastTicket = currentTicket;
               lastEntryTime = currentEntryTime;
              }
           }
        }
     }
   return lastTicket;
  }

// Last Trade Open price
double LastTradeOpenPrice(ulong lastTicket)
  {
   double lastOpenPrice = 0;
   if(lastTicket != 0)
     {
      if(PositionSelectByTicket(lastTicket))
        {
         if(PositionGetString(POSITION_SYMBOL) == _Symbol)
           {
            double lastBuyPrice = PositionGetDouble(POSITION_PRICE_OPEN);
           }
        }
     }
   return lastOpenPrice;
  }
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Price Constants - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Shakhrukh Bobojanov:
I am new in MQL5. I am struggling with writing a function to get last open trade ticket for a specific type and Open price of that ticket. Appreciate any help. 
You are comparing position type with order type.