
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
Closing order(s) in OnDeinit() is a bad idea. Change your mind and find an other way.
About your persisting problem, you just have to follow advice you get above (Keith and WHRoeder).
And what is your way?
And what is your way?
I've change a little bit of as follow:
As I remove the EA out of the chart I can see now the error messages as follow (screenshot):
If your goal is to close all orders use a script. When you decide to close, launch the script. Done.
What I want is, when I remove an EA, all the orders must be closed. This is somewhat like when you remove an indicator, all the objects must be removed or cleared, without running another script.
If you insist on using Bid and Ask instead of OrderClosePrice() you will need to call RefreshRates() before every attempt to close an order. Bid and Ask can get out of date when closing a number of trades.
You have been told that it is not a good idea to try to close trades in OnDeinit.
Why not use OnChartEvent with a keydown to disable the EA,close all trades and then ExpertRemove() to remove the EA once all trades are closed? If doing this, it makes sense to use MessageBox so that you can confirm in case of an accidental keystroke.
Mohamad Zulhairi Baba: I believe it's still possible counting up for closing order.
It's just that, the original code missing -1 in array.
it comply with FIFO requirement, when closing all order at once.
Thanks to all of you. I will consider your opinions and will have a try.