Discussion of article "Library for easy and quick development of MetaTrader programs (part XXXIV): Pending trading requests - removing and modifying orders and positions under certain conditions" - page 2
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Give your script to close positions.
here is the code:
here is another test; this time it didn't recognize closed positions, it missed them with previous ones in two cases.
2020.08.27 20:30:18.880 Expert mhdbzr-34 AUDCAD,H1: removed
2020.08.27 20:30:18.869 mhdbzr-34 AUDCAD,H1: uninit reason 1
2020.08.27 20:28:35.617 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position closed
2020.08.27 20:28:35.617 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position closed
2020.08.27 20:28:35.617 mhdbzr-34 AUDCAD,H1: - Position closed: 2020.08.27 18:58:03.000 - AUDCAD Closed Buy #573721560 at price 0.95218, Profit -2.29 USD
2020.08.27 20:28:35.614 mhdbzr-34 AUDCAD,H1: - Position closed: 2020.08.27 18:58:04.000 - AUDCAD Closed Buy #573721562 at price 0.95218, Profit -2.29 USD
2020.08.27 20:28:35.582 Script CloseTradesFast4Test AUDCAD,H1: removed
2020.08.27 20:28:35.577 CloseTradesFast4Test AUDCAD,H1: uninit reason 0
2020.08.27 20:28:35.577 CloseTradesFast4Test AUDCAD,H1: close #573721560 buy 0.10 AUDCAD at 0.95218 at price 0.95188
2020.08.27 20:28:35.177 CloseTradesFast4Test AUDCAD,H1: close #573721562 buy 0.10 AUDCAD at 0.95218 at price 0.95188
2020.08.27 20:28:35.161 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position closed
2020.08.27 20:28:35.158 mhdbzr-34 AUDCAD,H1: - Position closed: 2020.08.27 18:58:06.000 - AUDCAD Closed Sell #573721573 at price 0.95190, Profit -2.06 USD
2020.08.27 20:28:34.739 CloseTradesFast4Test AUDCAD,H1: close #573721571 buy 0.10 AUDCAD at 0.95224 at price 0.95191
2020.08.27 20:28:34.695 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position closed
2020.08.27 20:28:34.691 mhdbzr-34 AUDCAD,H1: - Position closed: 2020.08.27 18:58:06.000 - AUDCAD Closed Sell #573721573 at price 0.95190, Profit -2.06 USD
2020.08.27 20:28:34.306 CloseTradesFast4Test AUDCAD,H1: close #573721573 sell 0.10 AUDCAD at 0.95190 at price 0.95217
2020.08.27 20:28:34.180 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position closed
2020.08.27 20:28:34.177 mhdbzr-34 AUDCAD,H1: - Position closed: 2020.08.27 18:58:09.000 - AUDCAD Closed Sell #573721582 at price 0.95190, Profit -2.14 USD
2020.08.27 20:28:33.883 CloseTradesFast4Test AUDCAD,H1: close #573721577 sell 0.10 AUDCAD at 0.95190 at price 0.95217
2020.08.27 20:28:33.664 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position closed
2020.08.27 20:28:33.660 mhdbzr-34 AUDCAD,H1: - Position closed: 2020.08.27 18:58:09.000 - AUDCAD Closed Sell #573721582 at price 0.95190, Profit -2.14 USD
2020.08.27 20:28:33.440 CloseTradesFast4Test AUDCAD,H1: close #573721582 sell 0.10 AUDCAD at 0.95190 at price 0.95218
2020.08.27 20:28:32.946 CloseTradesFast4Test AUDCAD,H1: initialized
2020.08.27 20:28:32.928 Script CloseTradesFast4Test AUDCAD,H1: loaded successfully
2020.08.27 20:28:09.413 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position opened
2020.08.27 20:28:09.411 mhdbzr-34 AUDCAD,H1: - Position opened: 2020.08.27 18:58:09.000 - AUDCAD Opened 0.10 Sell #573721582 [0.10 Market-order Sell #573721582] at price 0.95190
2020.08.27 20:28:07.664 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position opened
2020.08.27 20:28:07.659 mhdbzr-34 AUDCAD,H1: - Position opened: 2020.08.27 18:58:07.000 - AUDCAD Opened 0.10 Sell #573721577 [0.10 Market-order Sell #573721577] at price 0.95190
2020.08.27 20:28:06.755 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position opened
2020.08.27 20:28:06.752 mhdbzr-34 AUDCAD,H1: - Position opened: 2020.08.27 18:58:06.000 - AUDCAD Opened 0.10 Sell #573721573 [0.10 Market-order Sell #573721573] at price 0.95190
2020.08.27 20:28:05.911 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position opened
2020.08.27 20:28:05.909 mhdbzr-34 AUDCAD,H1: - Position opened: 2020.08.27 18:58:05.000 - AUDCAD Opened 0.10 Buy #573721571 [0.10 Market-order Buy #573721571] at price 0.95224
2020.08.27 20:28:04.587 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position opened
2020.08.27 20:28:04.582 mhdbzr-34 AUDCAD,H1: - Position opened: 2020.08.27 18:58:04.000 - AUDCAD Opened 0.10 Buy #573721562 [0.10 Market-order Buy #573721562] at price 0.95218
2020.08.27 20:28:04.101 mhdbzr-34 AUDCAD,H1: OnDoEasyEvent: Position opened
2020.08.27 20:28:04.099 mhdbzr-34 AUDCAD,H1: - Position opened: 2020.08.27 18:58:03.000 - AUDCAD Opened 0.10 Buy #573721560 [0.10 Market-order Buy #573721560] at price 0.95218
2020.08.27 20:27:59.245 mhdbzr-34 AUDCAD,H1: initialized
2020.08.27 20:27:59.244 mhdbzr-34 AUDCAD,H1: Account 13278180: mhdbzr test (Alpari) 5537.01 USD, 1:100, Hedge, Demo account MetaTrader 4
2020.08.27 20:27:49.794 Expert TestDoEasy\Part34\mhdbzr-34 AUDCAD,H1: loaded successfully
I opened those trades manually on live market in demo account, not using tester environment. (and closed with the script as I did before)
(here is the screenshot to be sure it happened)
here is another test; this time it didn't recognize closed positions, it missed them with previous ones in two cases .
I opened those trades manually on live market in demo account , not using tester environment. (and closed with the script as I did before)
(here is the screenshot to be sure it happened)
I am looking for the cause of the problem. It won't be fast. Thanks for the tests.
I am looking for the cause of the problem. It won't be fast. Thanks for the tests.
(here is my opinion)
those closed positions are in the same second, one of them is handled in previous tick time, so in new tick, it has `new_history_orders=1` but two positions in the `list` and sorted probably wrong, because two items have same close time in second.
if the order is already in the list and throwing error message, then it delete position object and resume counting in this for loop, but I think it should not count n, when order has been delete inside the CreateNewEvent function, to catch next valid position.
also we need to understand recently handled positions, to skip wrong sorted orders and not counting down for `n`.
(here is my opinion)
those closed positions are in the same second, one of them is handled in previous tick time, so in new tick, it has ` new_history_orders =1` but two positions in the ` list ` and sorted probably wrong, because two items have same close time in second.
if the order is already in the list and throwing error message, then it delete position object and resume counting in this for loop, but I think it should not count n, when order has been delete inside the CreateNewEvent function , to catch next valid position.
also we need to understand recently handled positions, to skip wrong sorted orders and not counting down for `n`.
Thanks, I'll figure it out.
Hello Artyom, I remember you mentioning this future graphical shell the first time I read these articles some weeks ago... Can you provide more details about your vision for this and what it will allow us to do in practice?
Hello Artyom, I remember you mentioning this future graphical shell the first time I read these articles some weeks ago... Can you provide more details about your vision for this and what it will allow us to do in practice?
Ohoh ... Too broad a topic to tell in a nutshell like this ...
Almost every object will have its own graphic object, which allows displaying all its information about its "parent". Each object will be accessed from other objects - just like we now have access to different objects. All graphic objects will be able to interact with other objects. Each object will have its own type of graphical representation. There will be many types of graphic objects from which you can compose your own complex graphic objects. Each object will have the ability to interact with the mouse cursor and, accordingly, different reactions and handlers. As a result, it will be possible to create your own types of graphical representations for various objects and how they interact.
Did you ever polish and fix this issue in future chapters or did you forgot about this when you developed the graphical section? If you fixed and polished can you tell me in which chapter it is?
Thanks
Did you ever polish and fix this issue in future chapters or did you forgot about this when you developed the graphical section? If you fixed and polished can you tell me in which chapter it is?
Thanks