You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
So this means you have actually had the very same error in your own EA and definitely found that it happens in an otherwise correct OrderSend() call and is definitely an MT4 bug? Can you intentionally reproduce the error? Or are you also only speculating?
I used to be able to reproduce this reliably: I'd set some heavy-duty EAs going and, within an hour or so, I'd always get an incidence of this problem. But I haven't tried reproducing it in the 18 months since my post.
So this means you have actually had the very same error in your own EA and definitely found that it happens in an otherwise correct OrderSend() call and is definitely an MT4 bug? Can you intentionally reproduce the error? Or are you also only speculating?
It's an OrderSend function that is called at the same time from two instances of one EA. A race condition in OrderSend function. This is not reproducible during back-test because I can't simulate execution of 2 (or more) instances of one EA running in 2 (or more) different markets (someone might try it using a demo account).
You may write this test: 1/ run two instances of one EA code each operating on different market, both trading against one server, 2/ both EA instances must attempt to call OrderSend at the same time (at the same second, see it in both logs above) - each instance wants to open, 3/ one instance opens buy stop, second one a sell stop order. => no matter whether you check trade context before OrderSend, you will come to situation when the first EA instance is returned a trade number of trade that was open by second instance - the opposite positions will result in the error message. Collierab's EA got trade number of EURUSD trade in EA instance operating on GBPUSD. I got EURUSD trade in USDJPY market The only chance how to detect irrelevant trade number is to compare Symbol() to the OrderSymbol() of trade number (unless you run two instances in 1 market).
Try using a semaphore to avoid the problem
The code in https://www.mql5.com/en/articles/1412 does much the same general thing. It has the advantage of being fairly widely used. EAs which use the code in https://www.mql5.com/en/articles/1412 will all play nicely with each other. An EA which uses bespoke code for doing a similar thing will play nicely with multiple copies of itself, but not with other EAs. Therefore, there's a benefit in using the semi-standard code even if you think that you have a better version. (The crucial point is obviously using the same global variable which is used by https://www.mql5.com/en/articles/1412.)