Do action on waiting order execution?

 
Hi, is it possible to program mq4 to do some action at the moment of execution of a waiting order? For example, delete all pending orders or write info into an external file. OrdersTotal doesn't distinguish pending orders.
 
chrisperry:
OrdersTotal doesn't distinguish pending orders.
No, but OrderType does.
 
OK, so, what solution do you propose? I should do something like that: If there is one order (OrderTotals=1), the select it using OrdereSelect. If it is either buy or sell (OrderType = OP_BUY or OrderType = OP_SELL) then do the desired action... Not bad, but it would do the desired action over and over again, on every iteration of the script (untill there is an open BUY or SELL order). I need to do the action exctly one time, at the moment the order is executed.
 
chrisperry:
I need to do the action exctly one time, at the moment the order is executed.
Set a bool to true . . . . if it is true and the order has been activated, do the desired action and set the bool to false . . . then it only happens once.
 
OK, I'll try - I'm not very experienced programmer, so we'll see. If anyone comes with a diffeeent approach, I wold appreciate it. It is better to have multiple possible solutions.
 
OK, I'll try - I'm not very experienced programmer, so we'll see. If anyone comes with a diffeeent approach, I wold appreciate it. It is better to have multiple possible solutions.
 
int start(){
    static bool isWaiting = false;;
    if (isWaiting) for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS)                // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == chart.symbol             // and my pair.
    &&  OrderType()         <= OP_SELL                  // pending order opened
    ){
        doSomething();
    }
    isWaiting = false;  // One time only
    :
    int ticket = OrderSend(...); // Open a pending order
    if (ticket < 0) Alert("OrderSend failed: ", GetLastError());
    else            isWaiting = true;
Reason: