How to Turn MT4 Indicators into MT5 Within Minutes

 
Best Forex VPS for Singapore traders

How to Turn MT4 Indicators into MT5 Within Minutes: Do you want to convert the expert advisors made to operate on MT4 to ensures they can also operate on the MT5 platform?

No long methods here!

We’ll guide you in converting MQL4 code into MQL5 language code in such an easy way; you’ll be glad! The credits of the revolutionary MetaTrader series’ success goes to Metaquotes Inc, and now they’ve finally decided to mark the MT5 as its software for the future.

The company seems to focus the majority of its efforts on the MetaTrader 5 platform (MT5), and undoubtedly, it’s something better than the MT4.

So, how will you migrate? Keep reading!

Why Switch from MT4 to MT5 Within Minutes

The biggest query confronting programmers and traders with this planned migration is, how can you run the experts coded in MQL4 language on the MT5 platform efficiently, considering the fact that MT4 and MT5 can’t run on simultaneously.

When we go even deeper into this question, we come across some facts like:

  • The MT4 and MT5 can’t run using the identical programming languages. Hence, experts coded to work on the MT4 won’t work on the MT5, making the scene difficult.
  • MT4 has a very dull and boring future, and we can quote that after following the announcement regarding the MT4’s future updates. Hence, the software won’t have enough juice now.
  • Metaquotes has made numerous changes to the MT5’s functionality, due to which it gets more functional advantages in contrast to MT4.

How to Turn MT4 Indicators into MT5 successfully: The core process

Using MT4 EA on MT5 as it seems technically impossible, and the existing MQ4 EA’s source file needs to be modified (some elements of it) for making it work perfectly on MT5.

If you’ve got good knowledge regarding how MQL4’s language and environment vary from that of MQL4, then certainly, you can perform all those modifications.

Here, we’ll demonstrate the conversion of MT4 EA to MT5 format with the help of MT4 EA by Average.mq4 EA. The reason behind selecting it was, firstly, it comes pre-installed with all MT4 installations, and secondly, the majority of the programmers are familiar with this EA.

Using The Example “Moving Average.mq4” and Converting MT4 EA to MT5 EA

  • In MetaEditor 4, you’ll find the source file named “MQL4\Experts\Moving Average.mq4,” which you have to open.
  • Select + Copy All text by pressing Ctrl + A, Ctrl + C.
  • Press the F4 key and open the MetaEditor you find that the MT4 client terminal is open.
  • After you’ve successfully downloaded the MT5 desktop terminal from the desired broker, open the MT5 client’s instance.
  • Now, open MetaEditor 5 and create a new EA (template), something like we’ve demonstrated down there.
  • Fill the “Name” field, and assign a suitable name to your EA template. Once you’ve done that, you’ll get your forthcoming EA to be built on MT5.
  • Now, after selecting all text on the template by tapping Ctrl + A, and deleting them all, paste the text you copied from MT4.

MetaTrader 5 comes with other orders system, (for instance, open, close, select, send, and so on) methods. However, for the conversion from MT4 to MT5 EA, the easiest method as per our experts is using one library – mq4.mqh.

Further…

We suggest this library because it permits the programmer to operate with the orders in MQL5 the same way it was in the MQL4. In short, the library permits OLS (order language system) to become similar to that of MQL4.

You can get The mq4.mqh library file from chosen programmers online. We added a bit of functionality after obtaining ours from one such programmer. We combined everything into a single file. This library is meant to cover just the order systems.

  • Ensure that the MT5 platform’s instance is open
  • After getting the MT5 platform open, tap the File -> Open data folder” …\MQL5\Include.”
  • Drop the library file (mq4.mqh) to this folder.
  • Refreshing the MT5 platform is important now. Close it and open it again.
  • Now open MetaEditor5 and expert advisor’s source code.
  • In SimpleEA.mq5’s source code, add the string: #include <mq4.mqh>
  • After you add the string to the source code, press the “F7” button and assemble the SimpleEA.mq5’s source code. Also, there’s a “Compile” option mentioned on the MetaEditor 5’s toolbar.
  • After completing the assembling, you’ll get two errors. That’s where the distinction between MT4 and MT5 platforms is highlighted.

You just write iMA in MetaEditor 4, where “shift” is the price candle’s number. Handles are needed to be created for every single EA and function on MetaEditor5 to get value from the EA/indicator by that handle.

How to Turn MT4 Indicators into MT5 : Changing the source code

In this part, we’ll focus on editing the source code for MT4 to ensure that it works perfectly on MT5. These source code changes apply just on the indicator, as just one line in the source code is what you’re changing here.

How to Turn MT4 Indicators into MT5

Now, let’s describe the steps carrying on these changes. Shall we?

  • Create a variable Integer type for MA-indicator handle to kick-off the process.
  • Assign it a value called INVALID_HANDLE. The pic below explains the same.

How to Turn MT4 Indicators into MT5

Expert advisors and indicators come with the OnInit() section for initializations in runtime. The form is like:

MT4 to MT5

You can use the help file to read this. To access the Help File on MetaEditor5, just tap the “F1” key. You’ll also find one document on the MQL5 Community, providing you much info that you can find in the Help File. use this link for accessing this document –

https://www.mql5.com/en/docs/basis/function/events

  • Further, add this code (source code) into the text of our EA. In the absence of this section, press Alt + M from MetaEditor 5.

How to Turn MT4 Indicators into MT5

  • Five functions appear in the functions list, but you’ll see that the OnInit() function isn’t present there by default. So, we have to narrate it manually, and the image below will show you how to create it:

How to Turn MT4 Indicators into MT5

  • To see the OnInit() function paired to the source code, just tap Alt + M.

  • Now, write the following code in the section OnInit()

MT4 to MT5

In the MT4 MetaEditor, you generally need to write the following code:

On the other hand, the code is narrated as a handle for an indicator for the MT5, and that why you write the following code in MT5:

  • Now, to attain value from Moving Average EA, just write a function using the handle which you’ll see int he upcoming image:

How to Turn MT4 Indicators into MT5

As we discussed before, creating a function is necessary for getting the value for the EA/indicator using the MetaEditor5, and the function we use for getting values has a string which we call CopyBuffer().

Its job is to copy data from indicator to your array, and it gets data of a given buffer of a given indicator in a specific quantity.

Just go through the link -https://www.mql5.com/en/docs/series/copybuffer to read the document available.

The code is like:

MA has 1 buffer, numbered as“0”. Now, copy one value from MA. It’s written as follow in the MetaTrader4:

 

 

The last “0” matches to MA’s value on the last candle on the chart (zero candle). In the MT5 MetaEditor, you’ll get it written as follows:

 

  • From the index position, you have to Copy one value to the MA array.
  • While compiling the code, move to clear both the errors initially. To do this, point out the on the first record error, and perform a double click on it.
  • Now, you’ll move to the error’s location in the source code of MT5 for your EA. You’ll get the error code on line 114 for this instance.

How to Turn MT4 Indicators into MT5

 

  • You have to delete the line indicating the error and replace it with a string containing the MaGet(0) code, the way we’ve indicated down there.

The error code is always underlined in red ink, and you find the ma MaGet(0) code right underneath.

How to Turn MT4 Indicators into MT5

  • After removing the error code and putting the MaGet(0) string, there, you can press the F7 key and compile the code once again.
  • After compiling the source code, you’ll notice that only one error will appear now.
  • For replacing this last error code,the same sequence needs to be followed, that we adopted in clearing the previous error code. Reach the error code’s line, double click it, comment, and replace! That’s it!
  • You’ll find green ink underlining the error code. Right below, you’ll find the code, which will replace the error part. That’s how we eliminate the error.

MT4 to MT5

You have to use the following string for the replacement, and you’re on the verge:

if (Open[1]>MAGet(0) && Close[1]<MAGet(0)

  • After commenting and replacing the error code, the code’s compilation is compulsory. After compiling the source code the way we did earlier by tapping the F7 key, you’ll see that all errors are removed.
  • We’ve covered the whole process of converting the MT4 EA to a suitable version that you can use on MT5. As a result, you can conveniently run it on the MT5 platform now!

How to Turn MT4 Indicators into MT5 : The Conclusion

On the first look, How to Turn MT4 Indicators into MT5 seems a tough question to answer, but the method we mentioned above makes this happen. Just imagine how pathetic it would be to build the whole program on the MetaEditor 5 programming interface, and that too, right from scratch.

Luckily, the shortcut was available, and we described the same here. Recently, the usage of MT5 has increased significantly, and even new methods are expected to come up regarding the switching from MT4 to MT5. The MT5 platform is continuously developing.

The MT5 platform has gone through numerous modifications, and in the upcoming time also, we’re expecting a few more functions to be added. Undoubtedly, it’s far better than MT4.

New at Forex trade, or unhappy with your current Forex VPS hosting plan?

Well, Accuweb hosting’s Forex plans have set the new benchmarks for the Forex VPS hosting, presenting ultra-convenient plans at 6 different price points.

Users are cheerful with their Forex trading experience with these plans, and if you’re new to Forex, don’t miss out on the chance! You’re getting 7 days free trial also. Tap HERE to know more.

(Visited 27,064 times, 16 visits today)

Leave a Reply

AlphaOmega Captcha Classica  –  Enter Security Code
captcha      
 

This site uses Akismet to reduce spam. Learn how your comment data is processed.