Virtual - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources







This cross-platform allows the use of virtual trading environments in one of the easiest ways.
The library allows to create virtual trading environments and trade like a real trading environment. The functionality of this library is not new, although the provided cross-platform library has one property that may sometimes be important: you don't need to learn anything to use it . It is enough to understand the trading logic of MT4 (not MT5).
For virtual trading, choose MT4 style trading logic because it is more convenient and cross-platform EA can be easily developed.
Library functionality is traditionally demonstrated through pre-prepared examples.
// Start TS in real and virtual trading environments #include// https://www.mql5.com/en/code/16006 #include //Virtual trading environment Enter double lot size = 1 ; enter integer interval = 100 ; // Position lifetime input boolean example = true ; // what code example to choose //Reverse TS blank system() { if (! Order Select ( Total Orders () - 1 , SELECT_BY_POS )) Order sent ( _symbol , OP_BUY , MANY, symbol information double ( _symbol , SYMBOL_ASK ), 100 , 0 , 0 ); // If there is no position, open a position else if ( time current () - order opening time () > interval) // If the position lifetime exceeds the specified time { //Reverse position order closing ( booking (), order batch (), order closing price (), 100 ); OrderSend ( _symbol , 1 - OrderType (), Many, OrderClose (), 100 , 0 , 0 ); } } Blank check () { Static constant integer handle = VIRTUAL::Create(); // Create a virtual trading environment handle. 0 - real trading environment if (example) { if (virtual::SelectByHandle()) // Select the real trading environment system(); // Start TS (real) on the selected trading environment if (virtual::SelectByHandle(handle)) // Select the virtual trading environment { Virtual::NewTick(); // Add tick system() for virtual trading environment ; // Start TS on selected trading environment (virtual) } } Others // Alternative fixation for the same action. // Move along all existing trading contexts for ( integer i = 0 ; i <= virtual::total(); i++) if (virtual::select(i) by index) // Select the appropriate trading environment { Virtual::NewTick(); // Add a tick to the selected trading environment System(); // Launch TS on the selected trading environment } Comment (virtual::ToString()); // Display the status of the virtual trading environment on the chart }
This is a cross-platform reversal EA. Its trading logic can be described with a few strings ( system functionality) thanks to the MT4 style. The EA launches TS in both real and virtual trading environments. This can be clearly seen in the MT4 or MT5 tester (CTRL+F5)

The screenshots show that transactions are identical in real and virtual environments.
Note that the TS code remains unchanged . Choose only one trading environment: a real trading environment or any number of virtual trading environments.
The code shown here is redundant - these two versions just show the logic for using the library.
Since the tester acceleration scenario (see page 5 above) may be needed more frequently than other scenarios, we added the ability to switch any TS to the virtual environment and back by adding two strings at the beginning of the code.
#Define virtual tester // Launch in virtual trading environment #include//Virtual trading environment
Highlighted strings allow the user to not interfere with the TS original code.

This mode is specially designed for testers. Assume that long-term optimization is enabled ( virtual tester = true ) on a virtual environment rather than a real environment. This significantly improves optimization speed (time). The obtained results (OnTester Standard - Balance) can be used for a single run of the standard in a real trading environment ( Virtual Tester = False ).
Designed to speed up testers, identical two strings can solve another common problem - TS inversion.

reverse trade = true mode can reverse a trade. The internal algorithm is as follows:
Therefore, the EA logic is not violated in any way. At the same time, we can see what TS inversion provides. This mode also works for testers.
Attachment download
📎 string.mqh (0.59 KB)
📎 sync.mqh (5.42 KB)
📎 order.mqh (15.78 KB)
📎 orders.mqh (13.93 KB)
📎 virtual.mqh (23.14 KB)
📎 virtual_example.mq5 (1.92 KB)
Source: MQL5 #22577
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •