Experience with Migrating the MQL4 Projects to MQL5

 

Under pressure of prophesies made about the MQL4 future, I started with migration of my projects a couple of days ago, having no experience with MQL5. I am going to share some bits I experienced quite in the start:

  • Neither the MQL5 is bug-free. A bug in a simple string concatenation emerged. I believe that only + operator was affected, so I started replacing the + operator by StringAdd and StringConcatenate (uff, there are a lot of them in the code).
  • Many of the 'new' MQL4 functions do not have a direct counterpart in MQL5. No idea why they were introduced then.
  • On the other hand, MQL4 and MQL5 have a number of identical functions. At least I thought they had, until I realised, that they differed in arguments and/or returning values. It is pretty confusing. In fact the migration from 4 to 5 seems a bit safer, as the compiler often warns about the incorrect return value type, while the other way round the MQL5 does not use the return values in many cases.
  • In fact, there are two MT5 terminals, 32 and 64 bit version. Well, it is not a problem in most cases, but it makes the DLL imports vulnerable. In fact I need to have two compiled script versions if using the Winapi functions.
  • When the indicator initialisation fails in MQL5 (i.e. the OnInit returns a non-zero value), the indicator de-inits (so far so good) but then it remains attached to the chart, no message, no activity, (waiting for kinda resurrection?)
That's my first entry. I just started, so many more might follow.
 
Ovo Cz:

Under pressure of prophesies made about the MQL4 future, I started with migration of my projects a couple of days ago, having no experience with MQL5. I am going to share some bits I experienced quite in the start:

  • Neither the MQL5 is bug-free. A bug in a simple string concatenation emerged. I believe that only + operator was affected, so I started replacing the + operator by StringAdd and StringConcatenate (uff, there are a lot of them in the code).
Please pay attention that StringConcatenate() is not the same function on mql4 and mql5. (I know you already know but I want to highlight this for other people).
  • Many of the 'new' MQL4 functions do not have a direct counterpart in MQL5. No idea why they were introduced then.
Which ones ? some examples ?
  • On the other hand, MQL4 and MQL5 have a number of identical functions. At least I thought they had, until I realised, that they differed in arguments and/or returning values. It is pretty confusing. In fact the migration from 4 to 5 seems a bit safer, as the compiler often warns about the incorrect return value type, while the other way round the MQL5 does not use the return values in many cases.

ArrayMinimum(), ArrayMaximum() need to be checked carefully, StringConcatenate as noted above.

  • In fact, there are two MT5 terminals, 32 and 64 bit version. Well, it is not a problem in most cases, but it makes the DLL imports vulnerable. In fact I need to have two compiled script versions if using the Winapi functions.
  • When the indicator initialisation fails in MQL5 (i.e. the OnInit returns a non-zero value), the indicator de-inits (so far so good) but then it remains attached to the chart, no message, no activity, (waiting for kinda resurrection?)

I reported this to Metaquotes Service Desk, never got an answer. Seems it's a feature.

That's my first entry. I just started, so many more might follow.

Very good topic.
 

MT5 exists for a quite long period already, side by side with MT4, so there is a lot of articles and posts about migration. Many developers have libraries/includes of any kind which simplifiy porting experts and indicators from 4 to 5.

Bugs and new design decisions made by MQ are just there, and we can neither answer the questions "why" nor fix them here.

I'm not sure which issue with strings you're referring to. 

 
Stanislav Korotky:

MT5 exists for a quite long period already, side by side with MT4, so there is a lot of articles and post about migration. Many developers have libraries/includes of any kind which simplifiy porting experts and indicators from 4 to 5.

Bugs and new design decisions made by MQ are just there, and we can neither answer the questions "why" nor fix them here.

I'm not sure which issue with strings you're referring to. 

I also like to questioning why there must be a mq4 and mq5. Can't both been merged?
 
Stanislav Korotky:

....I'm not sure which issue with strings you're referring to. 

A bug occurred with a simple statement var1 = var1 + var2; The resulting string was not terminated at proper length and a lot of garbage (like Chinese art) was appended. It was reproducible, but too deep in my code to investigate systematically.

Stanislav Korotky:

Bugs and new design decisions made by MQ are just there, and we can neither answer the questions "why" nor fix them here.

 I did not ask for an answer nor fix. I am recording experience of a MQL5 noob, in case any other noobs would follow.

Alain Verleyen:
Please pay attention that StringConcatenate() is not the same function on mql4 and mql5. (I know you already know but I want to highlight this for other people).

Yes, very true, the StringConcatenate is extremely confusing, unlike the StringAdd, when it clears the first argument before appending the other arguments (which is not very intuitive).

 

So the next experience.

  • Conversion of the basic classes  (i.e. most of the include folder) was going so well, that I changed the strategy. Instead of copying  I linked the entire custom part of the 'include' folder from MQL4 to MQL5. Now I am checking and editing them, and nearly all the code can be expressed in a compatible syntax. Only exceptionally the conditional switch directive is required (#ifdef __MQL5__). I did not include the Orders engine though, which will need some analysis before coding, and probably hard times will come to make it compatible in some limited way.
  • The very tough part is code importing the Winapi. The 64-bit compatibility requires the pointers and handles declaration changed to 64-bit length, which appeared to have a deep impact to the code, as variables are hard-coded not only in their import declarations (the easier job), but also across the code (MQL4 had only the int type not very long time ago). Fortunately, I had many unit tests written for the Winapi in MQL4, so I am reusing them in the 64-bit environment.

 
Ovo Cz:

A bug occurred with a simple statement var1 = var1 + var2; The resulting string was not terminated at proper length and a lot of garbage (like Chinese art) was appended. It was reproducible, but too deep in my code to investigate systematically.

I use the operator for strings without problems. Perhaps it exists only in a specific version, and fixed/non-exstent in all the others.

Ovo Cz:

 I did not ask for an answer nor fix. I am recording experience of a MQL5 noob, in case any other noobs would follow.

Pardon me, but your first post contains the points 1 and 2: "Neither the MQL5 is bug-free." and "Many of the 'new' MQL4 functions do not have a direct counterpart in MQL5. No idea why they were introduced then.". Isn't this asking? If not, then please mark explicitly which parts of your messages require feedback, and which not. If we leave your remarks without solutions (for problems), it will hardly be an experience, but a lack of it ;-).

 
Bernhard Schweigert:
I also like to questioning why there must be a mq4 and mq5. Can't both been merged?

MQL4 and MQL5 are now the same single language. What you are referring to as different are MT4 and MT5 APIs.

I also do not understand why MQ decided to not support back-compatiility of MT4 APIs in MT5.

If more people ask this in the service-desk, they probably re-consider their decision.

 
Ovo Cz:

So the next experience.

  • Conversion of the basic classes  (i.e. most of the include folder) was going so well, that I changed the strategy. Instead of copying  I linked the entire custom part of the 'include' folder from MQL4 to MQL5. Now I am checking and editing them, and nearly all the code can be expressed in a compatible syntax. Only exceptionally the conditional switch directive is required (#ifdef __MQL5__). I did not include the Orders engine though, which will need some analysis before coding, and probably hard times will come to make it compatible in some limited way.
Did you see the MT4Orders project (no English version yet, you may use automatic translation)?
MT4Orders
MT4Orders
  • votes: 14
  • 2016.08.05
  • fxsaber
  • www.mql5.com
Параллельное использование ордерных систем MetaTrader 4 и MetaTrader 5.
 
Stanislav Korotky:
Did you see the MT4Orders project (no English version yet, you may use automatic translation)?
No, I definitively did not, thank you for the tip. I will check it a bit later, after I finish with the indicators, which seem less complicated to convert.
 
Stanislav Korotky:

I use the operator for strings without problems. Perhaps it exists only in a specific version, and fixed/non-exstent in all the others.

Pardon me, but your first post contains the points 1 and 2: "Neither the MQL5 is bug-free." and "Many of the 'new' MQL4 functions do not have a direct counterpart in MQL5. No idea why they were introduced then.". Isn't this asking? If not, then please mark explicitly which parts of your messages require feedback, and which not. If we leave your remarks without solutions (for problems), it will hardly be an experience, but a lack of it ;-).

Feedback is welcome anywhere, any time. Even though those points really were not meant to be queries, I appreciate your reaction.
Reason: