1

I'm trying to write a trade copier for MT4. I have already written one for MT5, but the issue I'm having with translation is in intercepting active orders. In MT5, this is relatively simple:

void OnTradeTransaction(const MqlTradeTransaction &trans, const MqlTradeRequest &request, 
   const MqlTradeResult &result) {
   // Code goes here
}

As shown in the MQL5 documentation, this event intercepts all orders sent from the client and accepted by a trade server.

Looking at the MQL4 documentation, however, I don't see any easy way of doing this. The closest I could get would be to iterate over all the orders by doing this:

for (int i = 0; i < OrdersTotal(); i++) {
    if (!OrderSelect(i, SELECT_BY_POS)) {
       // Error handling here
    }

    // Do stuff with this order
}

My understanding is that this code also gets all open orders. However, the issue I'm having is that there are key pieces of information that I cannot determine on these orders:

  1. Slippage
  2. Position-by (for close-by orders)
  3. Action type (close, close-by, delete, modify, send). Although this could be inferred from the fields populated on the order.

In my mind, I could then go and intercept the orders when they're generated (i.e. wrap OrderClose, OrderCloseBy, OrderDelete, OrderModify and OrderSend) and pull the relevant information off of the orders that way. But that still doesn't cover the case where the user enters an order manually.

Is there a way I can intercept all orders data without losing information?

Woody1193
  • 7,252
  • 5
  • 40
  • 90

0 Answers0