Error 1 (No error returned, but the result is unknown) on MQL4 OrderSend

 

Hi everyone,

I'm experiencing a pretty strange problem when trying to execute an OrderSend function using my EA (which is a web app running inside a browser component in MT4).

Most of the time the EA is used to set Pending Orders, but Market/Exchange Execution orders are also supported.

To get the problem I have to follow the procedure below:

  1. Start MT4, drag the EA onto a chart, pick an instrument and try to initiate the trade.
  2. This results in a successful order and I get the order ID in the response and the order shows up in the Trade tab.
  3. I either pick the same instrument or pick another one (usually doesn't matter) and try to initiate the trade.
  4. I now get an error code 1 and the message "No error returned, but the result is unknown".
  5. Restarting MT4 fixes the problem and I can successfully initiate the trade either on the same instrument as before or another instrument. 

This is the code responsible for executing OrderSend:

string parts[];
StringSplit(StringSubstr(message, StringLen("ORDERSEND:"), 0), '|', parts);
string symbolName = parts[0];
int digits = SymbolInfoInteger(symbolName, SYMBOL_DIGITS);
int cmd = StrToInteger(parts[1]);
double volume = NormalizeDouble(StrToDouble(parts[2]), digits);
double price = StrToDouble(parts[3]);
int slippage = StrToInteger(parts[4]);
double stoploss = NormalizeDouble(StrToDouble(parts[5]), digits);
double takeprofit = NormalizeDouble(StrToDouble(parts[6]), digits);
string comment = parts[7];
datetime expiration = StrToTime(parts[8]);
int result = OrderSend(symbolName, cmd, volume, price, slippage, stoploss, takeprofit, comment, 0, expiration, clrNONE);
int errorCode = GetLastError();
string responseMessage = result > 0 ? "Order was created successfully. Order ID: " + result : GetErrorDescription(errorCode);

Here are the strange things about this problem:

  1. The first attempt to execute the order pretty much always works (unless there is another obvious error like Invalid Trade Parameters, Invalid Stops etc, in which case another error is returned). Second or next attempts results in the "unknown result" issue.
  2. Restarting MT4 and retrying the order with the same parameters works (again only once, and after that I start getting the unknown result again).
  3. Unless there is another obvious problem, the first trade attempt after starting MT4 is always successful. There's never a "result is unknown" message on the first trade attempt after starting MT4.
  4. After restarting MT4 a few times, something happens and I am able to successully process multiple orders in a row (could be 10+). This lasts until MT4 is restarted and the issue occurs again - a successful order the first time, and subsequent attempts come back with "result is unknown". I can't figure out what needs to happen for these lucky conditions to be met. Both the "successful" and "unsuccessful" EA usage runs happen on any server (same IP/domain name is visible in the server config file for both successful and unsuccessful runs) and the configurations from my side (account, server etc) are exactly the same.
  5. I am not using OrderModify, where error 1 is a known behaviour. This is purely OrderSend.

Here is some output from my logs that shows that I'm trying to create orders with exactly the same parameters, and sometimes they work, and sometimes not, without any obvious reasons.

# SUCCESSFUL RUN - MULTIPLE ORDERS CAN BE SUBMITTED IN A ROW. NOTE A COUPLE OF SECONDS BETWEEN ORDERS.
15:11:55 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:11:55 ORDERRESULT:Order was created successfully. Order ID: 25055003
15:12:06 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:12:07 ORDERRESULT:Order was created successfully. Order ID: 25055012
15:12:11 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:12:12 ORDERRESULT:Order was created successfully. Order ID: 25055013
15:12:15 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:12:16 ORDERRESULT:Order was created successfully. Order ID: 25055016
15:12:19 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:12:20 ORDERRESULT:Order was created successfully. Order ID: 25055017
# RESTARTED MT4. TYPICAL (UNSUCCESSFUL) RUN START
15:12:47 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:12:48 ORDERRESULT:Order was created successfully. Order ID: 25055026
15:12:50 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:12:52 ORDERRESULT:No error returned, but the result is unknown
15:12:54 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:12:55 ORDERRESULT:No error returned, but the result is unknown
15:12:57 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:12:59 ORDERRESULT:No error returned, but the result is unknown
# RESTARTED MT4 AGAIN. TYPICAL (UNSUCCESSFUL) RUN, WHERE THE FIRST ORDER WORKS CORRECTLY AND NEXT ONES FAIL
15:13:45 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:13:46 ORDERRESULT:Order was created successfully. Order ID: 25055056
15:13:49 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:13:50 ORDERRESULT:No error returned, but the result is unknown
# RESTARTED MT4. SUCCESSFUL RUN START (MULTIPLE ORDERS CAN BE SUBMITTED IN A ROW).
15:14:07 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:14:07 ORDERRESULT:Order was created successfully. Order ID: 25055069
15:14:10 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:14:11 ORDERRESULT:Order was created successfully. Order ID: 25055072
15:14:14 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:14:15 ORDERRESULT:Order was created successfully. Order ID: 25055074
15:14:17 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:14:19 ORDERRESULT:Order was created successfully. Order ID: 25055076
15:14:21 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:14:22 ORDERRESULT:Order was created successfully. Order ID: 25055079
# RESTARTED MT4 AGAIN.
15:14:43 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:14:43 ORDERRESULT:Order was created successfully. Order ID: 25055088
15:14:47 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:14:47 ORDERRESULT:No error returned, but the result is unknown
15:14:50 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:14:51 ORDERRESULT:No error returned, but the result is unknown
15:14:54 ORDERSEND:USDCAD.p|2|0.01|1.28000|0|1.27350|1.29700|Test Comment|2022.05.3 18:00:00
15:14:55 ORDERRESULT:No error returned, but the result is unknown

Here's also the output from MT4 Journal log that corresponds to the above. During the unsuccessful runs, I am trying to submit the order with the same parameters, but there is no response received in the Journal.

0       15:11:55.835    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:11:55.946    '986188': order was opened : #25055003 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:07.842    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:07.967    '986188': order was opened : #25055012 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:12.857    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:12.996    '986188': order was opened : #25055013 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:16.862    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:16.975    '986188': order was opened : #25055016 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:20.349    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:20.473    '986188': order was opened : #25055017 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
2       15:12:24.445    Expert Disney,H1: removed
0       15:12:36.673    MT4 build 1355 started
0       15:12:36.674    Windows 10 Pro x64, IE 11, UAC, 8 x Intel Core i7-8565U  @ 1.80GHz, Memory: 6210 / 16163 Mb, Disk: 274 / 475 Gb, GMT+1
2       15:12:38.268    Expert Disney,H1: loaded successfully
0       15:12:39.072    '986188': login on BROKER_SERVER through Server 4D (ping: 32.44 ms)
0       15:12:39.433    '986188': login datacenter on BROKER_SERVER through Server 4D (ping: 32.44 ms)
0       15:12:39.632    '986188': previous successful authorization performed from 62.174.173.195
0       15:12:48.162    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:48.272    '986188': order was opened : #25055026 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:52.172    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:55.607    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:12:59.099    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
2       15:13:29.949    Expert Disney,H1: removed
0       15:13:33.583    MT4 build 1355 started
0       15:13:33.583    Windows 10 Pro x64, IE 11, UAC, 8 x Intel Core i7-8565U  @ 1.80GHz, Memory: 6108 / 16163 Mb, Disk: 274 / 475 Gb, GMT+1
2       15:13:35.225    Expert Disney,H1: loaded successfully
0       15:13:35.994    '986188': login on BROKER_SERVER through Server 4D (ping: 32.44 ms)
0       15:13:36.345    '986188': login datacenter on BROKER_SERVER through Server 4D (ping: 32.44 ms)
0       15:13:36.550    '986188': previous successful authorization performed from 62.174.173.195
0       15:13:46.110    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:13:46.234    '986188': order was opened : #25055056 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:13:50.106    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
2       15:13:53.021    Expert Disney,H1: removed
0       15:13:54.935    MT4 build 1355 started
0       15:13:54.935    Windows 10 Pro x64, IE 11, UAC, 8 x Intel Core i7-8565U  @ 1.80GHz, Memory: 5935 / 16163 Mb, Disk: 274 / 475 Gb, GMT+1
2       15:13:56.615    Expert Disney,H1: loaded successfully
0       15:13:57.374    '986188': login on BROKER_SERVER through Server 4D (ping: 32.44 ms)
0       15:13:57.737    '986188': login datacenter on BROKER_SERVER through Server 4D (ping: 32.44 ms)
0       15:13:57.992    '986188': previous successful authorization performed from 62.174.173.195
0       15:14:07.568    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:07.708    '986188': order was opened : #25055069 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:11.568    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:11.723    '986188': order was opened : #25055072 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:15.575    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:15.680    '986188': order was opened : #25055074 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:19.159    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:19.258    '986188': order was opened : #25055076 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:22.583    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:22.737    '986188': order was opened : #25055079 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
2       15:14:25.649    Expert Disney,H1: removed
0       15:14:32.124    MT4 build 1355 started
0       15:14:32.124    Windows 10 Pro x64, IE 11, UAC, 8 x Intel Core i7-8565U  @ 1.80GHz, Memory: 6163 / 16163 Mb, Disk: 274 / 475 Gb, GMT+1
2       15:14:33.780    Expert Disney,H1: loaded successfully
0       15:14:34.529    '986188': login on BROKER_SERVER through Server 4D (ping: 32.44 ms)
0       15:14:34.860    '986188': login datacenter on BROKER_SERVER through Server 4D (ping: 32.44 ms)
0       15:14:35.070    '986188': previous successful authorization performed from 62.174.173.195
0       15:14:43.704    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:43.838    '986188': order was opened : #25055088 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:47.703    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:51.701    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:55.235    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700

Any help is greatly appreciated.

If I can provide any more information - let me know.

OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderSend - Trade Functions - MQL4 Reference
 

Looks to me like you have a four (4) second trade timeout (no reply from the server). That is quite small, Connection timeout is ≈30. You might try:

  1. Pinging or Trace route to the server to see if you have network problems.
  2. An initial delay on the first tick (there is a lot of chart update traffic before).
  3. Talking with your broker. Should the timeout be enlarged, do they have overloading?
 
William Roeder #:

Looks to me like you have a four (4) second trade timeout (no reply from the server). That is quite small, Connection timeout is ≈30. You might try:

  1. Pinging or Trace route to the server to see if you have network problems.
  2. An initial delay on the first tick (there is a lot of chart update traffic before).
  3. Talking with your broker. Should the timeout be enlarged, do they have overloading?

Thanks for the response William. 

0       15:14:43.704    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:43.838    '986188': order was opened : #25055088 buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:47.703    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:51.701    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700
0       15:14:55.235    '986188': pending order buy limit 0.01 USDCAD.p at 1.28000 sl: 1.27350 tp: 1.29700

The last 3 entries here is me trying to initiate the trade via the EA (which is done by a button click). The first entry is the successful order creation. If I wait longer, nothing is output in the Journal (and the "result is unknown" message appears pretty much instantly in my logs). Is this why it seems like there is a 4 second trade timeout?

  1. I'll investigate the connection problems a bit more, but it shouldn't be the case as the connection status indicator in the bottom right corner of MT is not showing any signs of problems and I'm also constantly getting the price data correctly.
  2. Can you please clarify how I could implement the delay on the first tick? What usually happens in the EA is that a button is clicked at any time (could be immediately after the EA start, but could be after a minute or more), at which point I start executing OrderSend.
  3. This happens with several brokers and both on Demo and Live accounts.
 
  1. If you have a net problem, the automatic resend will hide the “showing any signs.”

  2. When in doubt, think:

    bool isFirstTick;
    void OnInit(){ isFirstTick=true; … }
    void OnTick(){ 
       if(isFirstTick){ isFirstTick=false; sleep(10); }
       ⋮
    }

  3. Several different brokers sounds like your network/your hardware.