Discussion of article "Library for easy and quick development of MetaTrader programs (part X): Compatibility with MQL4 - Events of opening a position and activating pending orders"
In MT4 there is a bug that deletes everything, including HIDDEN objects (which should not be) by pressing the ← Backspace key.
So by pressing ← Backspace you can easily delete your entire interface.
In general, your MT4 code lacks a response to deleting controls to recreate them.
Trade.mqh was made working for MT4.

- www.mql5.com
#ifdef __MQL5__ #define __MQL5_NEW__ #else // __MQL5__ #define __MQL4_NEW__ #endif // __MQL5__at the beginning of the bible. And all conditions should be changed to New-variant. Then it will be possible to run in MT5 the mt4-variant of the library, and in MT4 - the mt5-variant of the library.
I suggest to do at the very beginning of the bibles. And all conditions should be changed to New-variant. Then it will be possible to run in MT5 the mt4-variant of the library, and in MT4 - the mt5-variant of the library.
There is only one library variant
I would like to be able to run MT4-logic of the library in MT5.
I would like to be able to run MT4 library logic in MT5.
I didn't understand the suggestion because the logic is the same for both platforms. The implementation is slightly different.
I connect MT4Orders before your library. And I want MT4 variant to be involved in your library.
There are two ways to solve this
- I replace __MQLX__ in all sources of your library. That is, I change the library itself, albeit semi-automatically.
- You create macros, as I showed above. Then to include MT4-logic in MT5 you don't need to change anything in your library.
I think you will be interested to compare your library exclusively in MT5, but in two logic modes.
ZY I also want to be able to run your library in Virtual. For this I need to have access to MT4-style part of the library.
I connect MT4Orders before your library. And I want to use MT4 variant in your library.
There are two ways to solve this
- I replace __MQLX__ in all sources of your library. That is, I change the library itself, albeit semi-automatically.
- You create macros, as I showed above. Then to include MT4-logic in MT5 you don't need to change anything in your library.
I think it would be interesting for you to compare your library exclusively in MT5, but in two logic modes.
ZY I also want to be able to run your library in Virtual. For this purpose I need to have access to MT4-style part of the library.
We can discuss this. But in private. For now the library will be developed in the same way - one logic for both platforms. The library was conceived as an independent unit - one for both platforms. With the same logic that does not contradict either MQL4-style or MQL5-style - everything is common.
ZY. I haven't understood what is meant by MQL4-style part of the library. There is no separation there. Show me the place in the library that is mentioned.
We can discuss it. But in private. In the meantime, the library will be developed in the same way - one logic for both platforms. The library was conceived as an independent unit - one for both platforms. With the same logic that does not contradict neither MQL4-style nor MQL5-style - everything is common.
I have sent you a version of your library, which works in MT5 through MT4-style logic prescribed by you.
ZY. I have not understood what is meant by the MQL4-style part of the library. There is no separation there. Show me the place in the library that is mentioned.
The point is that cross-platform libraries have a much higher probability of operability of MQL4-style part of the library than MQL5-style. Therefore, when using cross-platform libraries, I prefer to use their MQL4-style logic in MT5. It is much more reliable in MT5.
I think that in MT5 your MQL5-style logic will take a long time to detect bugs, while MQL4-style will have only a minimum number of bugs and not critical ones.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Library for easy and quick development of MetaTrader programs (part X): Compatibility with MQL4 - Events of opening a position and activating pending orders has been published:
In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. In the ninth part, we started improving the library classes for working with MQL4. Here we will continue improving the library to ensure its full compatibility with MQL4.
Testing
Let's check the applied changes. Compile the TestDoEasyPart10.mq4, launch it in the tester, open and close positions, place pending orders, wait till one of them is activated and check if stop levels and trailing are activated (modifying positions and pending orders). All events the library "sees" for MQL4 are to be displayed in the tester journal:
If we carefully observe the tester journal, we can see that the library still cannot see closing positions. When the BuyLimit #3 pending order is triggered, the journal entry informs that the [BuyLimit #3] is activated leading to the Buy #3 position. Now the library sees the events of pending order activation and knows a source order a position originated from. Besides, we can see a slight omission in the modification function — the label of the BuyStop #1 pending order modified by trailing becomes red. But the library sees all order and position modification events.
Author: Artyom Trishkin