Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
2016.10.10 15:31
2021.06.02 08:33
\MQL5\Experts\ \MQL5\Include\
MT4Orders.mqh (220.2 KB) view
report_strict.mq4 (20.27 KB) view
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

This library allows to work with the orders in MQL5 (MT5-hedge) in the same way as in MQL4.

That is, the order language system (OLS) becomes identical to MQL4. At the same time, it is still possible to use the MQL5 order system in parallel. In particular, the standard MQL5 library will continue to fully operate.

It is not necessary to choose between the order systems. Use them in parallel! When translating MQL4 -> MQL5, there is no need to touch the order system at all.

It is sufficient to add a single line at the beginning:

#include <MT4Orders.mqh> // if there is #include <Trade/Trade.mqh>, add this line AFTER that

Similar actions (adding one line) in your MQL5 codes allow to add the MT4 OLS to the MT5 OLS, or completely replace it.

The author had created this feature for himself, therefore, he deliberately had not applied the same idea of "one-line" transfer for timeseries, graphical objects, indicators, etc.

This work covers only the order system.

The task of possibility to create a complete library for allowing the MQL4 code to work in MetaTrader 5 without changes had not been considered.

As an example, multiple MT4/5 Expert Advisors (from the codebase) of different types have been used: scalpers, news trading experts, martingales, multi-currency experts, etc.

Here (parallelism of the MT4 and MT5 OLS) is how they can be used in the MT5 tester (or demo):

// MQL4&5-code

#define OnTick MTstart
#define start  MTstart

#ifdef __MQL5__

// Select the required MT5 EA
// #include "Lucky.mq5"               //
// #include "Puria.mq5"               //
// #include "Ilan_1_6_Dynamic_HT.mq5" //
// #include "Multik.mq5"              //
// #include "VLT_Trader.mq5"          //
// #include "Exp_PFE_Extr.mq5"        //

#endif // __MQL5__

#include <MT4Orders.mqh> // if there is #include <Trade/Trade.mqh>, add this line AFTER that

#include <MQL4_to_MQL5.mqh> // ONLY for this example

// Select the required MT4 EA
// #include "Lucky.mq4"          //
// #include "E-news-lucky6.mq4"  //
// #include "cm_ea_news.mq4"     //
// #include "Spreader_v2.mq4"    //
#include "Ilan1_4_strict.mq4" // #property strict (MQL5), original -

#include "OrdersToString.mqh"

#undef OnTick

void OnTick( void )

  if (MQLInfoInteger(MQL_VISUAL_MODE))
    Comment("Trade:" + OrdersToString() + "\nHistory:" + OrdersToString(MODE_HISTORY)); // can be viewed in visual mode of the tester


If earlier it was possible to test the MT4 experts on real ticks in the MetaTrader 4 tester, now the MT5 tester has the multi-currency capabilities. That is, the multi-currency MT4 experts can now be tested directly in the tester!

An additional example is a statistical script, collected from multiple MT4 samples:

// MQL4&5-code

#include <MT4Orders.mqh> // if there is #include <Trade/Trade.mqh>, add this line AFTER that

#include <MQL4_to_MQL5.mqh> // ONLY for this example

#ifdef __MQL5__
  #property script_show_inputs

  void OnStart( void )
    ::OnStartScript();  // TradingSystemRating_Script_Ad.mq4

    ::WriteDealsInfo(); // b-SharingDoW.mqh

    // Report_strict.mq4

    MessageBox("Look in MQL5\\Files");

#endif // __MQL5__

#define OnStart OnStartScript

#include "TradingSystemRating_Script_Ad.mq4" //

#include <b-SharingDoW.mqh> //
sinput int MAGIC = 0;       // MagicNumber of the evaluated orders (b-SharingDoW.mqh)

// Disregard the Warnings - script has been written in 2006...
#define i ii // avoid the Warnings part
#include "Report_strict.mq4" // #property strict (MQL5), original -

Translated from Russian by MetaQuotes Ltd.
Original code:

i-CAiChannel i-CAiChannel

The Envelopes indicator with the use of the i-CAi indicator algorithm.

i-CAi_Digit i-CAi_Digit

The i-CAi indicator displays the most recent value as a price label with the the possibility to round the channel levels up to a required number of digits.

i-CAiChannel_System_Digit i-CAiChannel_System_Digit

The indicator implements a breakthrough system using the i-CAiChannel channel.

Exp_i-CAi_StDev Exp_i-CAi_StDev

Trading system based on the signals of the i-CAi_StDev indicator.