- Introduction to Importing External Source Code Files in MQL5 (00:00 – 00:17)
- Introduction to the tutorial on how to import external source code files in MQL5, focusing on an external source code file for the MACD indicator.
- Opening MetaEditor and Creating a New Expert Advisor File (00:17 – 00:43)
- Instructions on opening MetaEditor in MetaTrader and creating a new Expert Advisor file named “Simple Source Code Import”.
- Setting Up the Code Structure and Including Trade.mqh (00:43 – 01:09)
- Deleting unnecessary code and including the ‘Trade.mqh’ library, which is a standard MQL5 source code file.
- Explanation of MQL5 Libraries and Source Code Files (01:09 – 02:03)
- Discussing the nature of MQL5 libraries and source code files, and their location in the MQL5 directory.
- Importing a Custom MQL5 Source Code File (02:03 – 02:57)
- Demonstrating how to import a custom MQL5 source code file named ‘Check Entry_MACD’, located in a custom ‘Import’ folder.
- Using the Imported Function and Displaying the Signal (02:57 – 03:29)
- Implementing the ‘Check Entry’ function from the imported file to calculate and display buy or sell signals on the chart.
- Compiling the Code and Demonstrating the Expert Advisor (03:29 – 04:45)
- Compiling the code in MetaEditor and demonstrating the Expert Advisor in MetaTrader, showing how it calculates buy and sell signals using the MACD entry.
- Importing and Testing Another Module (RSI) (04:45 – 05:39)
- Importing the RSI module, recompiling the code, and testing the Expert Advisor in MetaTrader to show how it calculates RSI signals.
- Conclusion and Benefits of Using Modular Files (05:39 – 05:57)
- Concluding the tutorial by highlighting the benefits of using modular files in MQL5, which can be coded once and reused multiple times.
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.