Please help determine the trade type of the last open order

To add comments, please log in or register
Peter Kaiza
930
Peter Kaiza  

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);
}
Peter Kaiza
930
Peter Kaiza  
Please help!! 
Keith Watford
Moderator
20339
Keith Watford  

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().

nicholi shen
2392
nicholi shen  
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)
      ...
}

Peter Kaiza
930
Peter Kaiza  
nicholi shen:
Thanks nicholi, it works 
To add comments, please log in or register