MQL5 TUTORIAL BASICS – 37 SIMPLE SOURCECODE IMPORT

video

In this video we want to find out how to import external source code files, in this case, we have an external source code file for the macd indicator, so let’s find out how to do that with mql5.
To get started please click on the little icon here or press F4 in your Metatrader, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple source code import, click on continue, continue and finish, now you can delete everything above the on tick function and the two command lines here.
We start with an include statement, you may already know that from other videos where we have included the file that is called trade dot mqh.
Trade dot mqh is what we call a library, basically, it’s a source code file, it is one of the files that are provided with mql5, here it is and it is located in the folder mql5, include, trade. As you can see there are lots of other mqh files, like in this folder and this is also true for the other folders here, it is possible to open one of these files with any kind of editor and you will find hundreds and hundreds of lines with source code and in our case we want to import a self-created mql5 source code file, the name is check entry underscore macd, it is located in the folder import that I have created below the folder where I have stored the file for the simple source code import. And what this file basically does is it will use the macd indicator to calculate a signal and it will return a buy or a sell signal, and to get that signal I just use a function that is contained inside of the source code, it is called check entry and we create a string variable called signal that will be filled with the return value of the check entry function, it will output the signal on the chart by using the comment statement so we will see the text signal and the calculated signal and that’s basically all.
I can now click on the compile button, the code is compiled successfully but to make this work for you, you would need to have the right source file here, let me show you something, these are all source files for different entries that are used in the professional version for the robot trading system. This is the macd and I would like to also copy the rsi to show you how it’s done, and now I paste both files into the import folder so we have already compiled the code I can now click this little button to go back to Metatrader, here we click on view, strategy tester or press ctrl and r, here I pick the new file simple source code import dot ex5, I mark the visualization option here and I start a test, and here you can see that the expert advisor is calculating buy and sell signals for the macd entry, so let’s click on stop.
Now I want to import the rsi module, I click on compile, this also worked without any errors so now I go back to Metatrader, I stop the current test, start a new one, and now it’s calculating the rsi signal.
And this is actually possible for all the modules that you see here, I have coded lots of them and that’s the power of the include statement, it makes it possible to import source code files that have been created by anybody else or maybe even by you, these are modular files that you just have to code once and you can use them over and over again, and now you know how to do that for an mql5 expert advisor and you have coded it yourself with a few lines of mql5 code.