Checking for absolute last Close Order value and details upon running EA - help please.

 
Hello gang:

Let's say I begin my EA in the start section with a check on Open Orders with the OrdersTotal() function. If OrdersTotal()>0 then do some other logical analysis, but if OrdersTotal()<1 (meaning no open orders), then how can I immediately query what the last close order was, and whether it was a buy closing a short, or a short closing a buy?

Could anyone please provide me with the actual code to perform this (simple) operation?

Assume, for the moment, that if OrdersTotal<1, it's because a position just closed, and I want to know how the last order closed (either with a buy or sell), because I wish to perform different calculations and operations based on the return value for what the last close order was.


Many thanks,
Andre
 
andrenogues:
how can I immediately query what the last close order was, and whether it was a buy closing a short, or a short closing a buy?
int LastClosedTicket=0; datetime LastClosedTime;
    for(int pos=0; pos < HistoryTotal(); pos++) if (
        OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders
    &&  OrderCloseTime()    > lastClosedTime            // not yet processed,
    &&  OrderMagicNumber()  == magic.number             // w/ my magic number,
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderType()         <= OP_SELL){    // Avoid cr/bal https://forum.mql4.com/32363
    LastClosedTicket = OrderTicket(); LastClosedTime = OrderCloseTime();
}
if (LastClosedTicket > 0 && OrderSelect(LastClosedTicket, SELECT_BY_TICKET, MODE_HISTORY)){
   if (OrderType() == OP_BUY) {...
}
Reason: