How to Determine When a Pending Order Has Been Filled

 

Does Anyone know how to determine when a pending order is filled, so that it is now an open order?

I want to develop an EA which places a pending buy order and a pending sell order, and then subsequently

cancels whichever one is still pending after one of them is filled.

Thanks,

Dennis

 
if (OrderType()==OP_BUY || OrderType()==OP_SELL){

 //Order has been filled

} 
 
dennisne:

Does Anyone know how to determine when a pending order is filled, so that it is now an open order?

I want to develop an EA which places a pending buy order and a pending sell order, and then subsequently

cancels whichever one is still pending after one of them is filled.

    int openTicket=0, pendTicket=0;
    for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
//  &&  OrderMagicNumber() == magic.number              // my magic number
    &&  OrderSymbol()      == Symbol() ){               // and symbol
        if (OrderType() <= OP_SELL) openTicket=OrderTicket();
        else                        pendTicket=OrderTicket();
    }
    if (openTicket != 0 && pendTicket != 0) OrderDelete(pendTicket);
Reason: