OnTradeTransaction : Not Catching Enough Events When Performing Close All Positions Bulk Operation

 

I tested this code without errors when closing each position one at a time. But when performing Close All Positions Bulk Operation, it does not recognize enough events. You can watch the video for more information. 

int OnInit() {
//---

  return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason) {

}

void OnTick() {

}

//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result) {
  CheckRequestType(trans, request, result);
}

void CheckRequestType(const MqlTradeTransaction& trans,
                      const MqlTradeRequest& request,
                      const MqlTradeResult& result) {
  switch(request.action) {
    case TRADE_ACTION_DEAL: { 
      if(request.position == 0) {
        Print("Open Position: ", request.order);
      }
      else {
        Print("Close Position: ", request.position);
      }
      break;
    }
  }
}
//+------------------------------------------------------------------+



 
Le Minh Duc:

I tested this code without errors when closing each position one at a time. But when performing Close All Positions Bulk Operation, it does not recognize enough events. You can watch the video for more information. 



I might be wrong but from my memory, aren't you supposed to retrieve the type of "trans" in your case using something like trans.type and switch the value you get with an ENUM_TRADE_TRANSACTION_TYPE ? (Instead of request.action).

 
Le Minh Duc:

I tested this code without errors when closing each position one at a time. But when performing Close All Positions Bulk Operation, it does not recognize enough events. You can watch the video for more information. 



Your code is wrong. A bulk operation doesn't send a request with an action TRADE_ACTION_DEAL.
 
Alain Verleyen #:
Your code is wrong. A bulk operation doesn't send a request with an action TRADE_ACTION_DEAL.

You are wrong, It will send actions TRADE_ACTION_DEAL if I close all the positions with the same direction

 
Update:
I just tested again, the reason is that when closing 2 orders in opposite directions, it will generate a request TRADE_ACTION_CLOSE_BY instead of two of TRADE_ACTION_DEAL
 
Le Minh Duc #:
Update:
I just tested again, the reason is that when closing 2 orders in opposite directions, it will generate a request TRADE_ACTION_CLOSE_BY instead of two of TRADE_ACTION_DEAL
So who is wrong ?
 
Alain Verleyen #:
So who is wrong ?

both you and me

 
Le Minh Duc #:

both you and me