What Happens When OrderSend() Doesn't Fill?

To add comments, please log in or register

Hello Folks, 

Can I pick the brains of some MQL experts please?

I use an EA to allow me to trade whilst I'm at work; before work I configure the EA based an expected market pattern - if price action follows a forecast path, if/when price then enters what I call the 'sweet spot', using the inputs I've set up in the morning the EA will send the OrderSend() function to send just one order. I ensure only one order is sent by having coded 1) a check for no existing/open orders and 2) my account balance is unchanged from when I analysed the market beforehand (if it were different would suggest an order has been opened since I analysed).

Now, something I want to understand is:

I have two brokers: an ECN broker and a Spread Bet. On two consecutive days the OrderSend() function has been called on both accounts for the same price action, same pair, same price, same time. On my ECN, for both days the OrderSend() has sent and the order has filled with no issue. There was only one call for the OrderSend() and one order placed - perfect. However, for my Spread Bet, the OrderSend() function sent 6 times (I have coded in a notification to be sent to my phone when the order sends) and no physical order materialised. There's no information in the 'journal' of MT4 - suggesting there wasn't a daft issue such as lack of margin, incorrect stops, etc. I also have a wide slippage allowance (far beyond slippage you'd see on a normal, none news day) in both my MT4 account and the sending of OrderSend() so this isn't cause. I infer the order of events to be:

1) The OrderSend() sent as intended when price was within the 'sweet spot'.

2) A physical order did not materialise. 

3) With price still in the 'sweet spot' and no physical order or change to account balance (due to no order being placed) the OrderSend() function sent again. 

4) Steps 1-3 repeated 6 times. 

5) Price action left the 'sweet spot' and no subsequent tries were made. 

This leaves me with two questions:

1) The first, most importantly,  what's the process flow between OrderSend() and a physical order? What I'm looking to understand is: could the 6 instances of OrderSend() have lead to 6 physical orders, or, was the order sent, killed, sent, killed, and so on, or, could the orders have sat stagnant with my broker until all of them were accepted?

2) Do we believe this to be a case of latency in the execution of my Spread Bet broker? Perhaps coincidence, but it seems suggestive given on both days my ECN executed with no issue. 

Keen for your thoughts. 

Thanks All!


nicholi shen
nicholi shen  

There's no telling what's wrong with your EA without seeing the code, however, I suspect you have an issue with the way it is formatting the order. An ECN broker ignores the data sent with OrderSend and only evaluates the order-type, SL, and TP. It will fill at the market rate no matter what you put in for the execution price and slippage. Your first step will need to include some debugging in your EA. You'll want to catch the last error after a failed OrderSend and send that as a notification. 

#include <stdlib.mqh>
void OnTick()
   int ticket = OrderSend(
      "This is an example",
   if(ticket < 0){
         "OrderSendError: %s",

Hi Nicholi, 

Thanks ever so much for getting back to me so quickly!

That's great to know - learning for me as I didn't know that, thank you. 

As a test, during a period of low liquidity I sent an OrderSend() on my Spread Bet using a lot size of 0.01 and that had no issue - the order sent and filled with no problem, which, I think suggests the broker is happy with the formatting. The issue seems to only happen when the market is in full flow - what would your thoughts on that be?

I really appreciate the piece of code for retrieving errors - I'm adding it now. 

Thank you again, 


To add comments, please log in or register