Please help determine the trade type of the last open order

 

I got this function that selects the latest open  order .Now I want to determine whether this order is a buy or sell, how do i proceed from here?

Will this work?

if LastOpenTicket() == OP_BUY

)

the Do this......

)

My question is , will the programme be able to tell if the last open  ticket is a buy or sell or do i need further code?

  int LastOpenTicket(){
    datetime lastTime  = 0;
    int      lastTicket = -1; // None open.
    for(int i=OrdersTotal()-1;i>=0;i--) if (
        OrderSelect(i, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == MagicNumber             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderOpenTime()     >  lastTime
    ){
      lastTime   = OrderOpenTime();
      lastTicket = OrderTicket();
    }
    return(lastTicket);
}
 
Please help!! 
 

LastOpenTicket() returns the ticket number so you have to reselect it and check whether it is a buy or sell.

Or you could pass a variable by reference to the function

Or use a global scope variable to hold the OrderType().

 
prweza:
Please help!! 
int order_type(const int ticket)
{
   if(OrderSelect(ticket, SELECT_BY_TICKET))
      return OrderType();
   return -1
}

{
   if(order_type(LastOpenTicket()) == OP_BUY)
      ...
}

 
nicholi shen:
Thanks nicholi, it works 
Reason: