In this video I would like to show you something, it’s how to import external source codes.
This is a strategy test and when I click on stop you will see that we have an rsi signal here that’s actually what’s calculated inside of the strategy test but you don’t see anything because I didn’t change the template so far and its possible to exchange the module, the external source code. If you click on the include folder inside of your Metatrader installation directory, you will see files that have the extension mqh.
There are lots and lots of files inside of those folders and you can open them with Metaeditor or with any editor and this is what you see. This is all source code, its readable for humans, these are hundreds and hundreds of lines of source code, they are provided by Metaquotes but we want to find out how to import our own source codes, so please click on the little button here or press F4.
Now you should see the Metaeditor window and here you want to click on file, new, 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 comment lines here.
We start by using an include statement, I would like to use a file that is located inside of a folder that is called import.
I have created this folder and the file I would like to import is called check entry underscore macd, this is an mq4 file so it’s a source code file, so I don’t have to write all the source code again, I just do it once for each entry and I can import it over and over again in all of my systems.
Now we will create a string variable that is called signal and it will call a function that is called check entry to get the signal for the macd, and finally, we will use the comment statement to output the word signal, followed by the calculated signal and that’s all.
Now I can click on the compile button, and it works without any errors but remember you would need to have the same source code file here otherwise the compilation process will not work.
In my case, I can click on the little button here or press F4 to go back to Metatrader.
Now I click on view, strategy tester or press ctrl and r, I pick the new file simple source code import dot ex4, enable the visual mode here and start a test.
Here is the expert advisor, it creates buy and sell signals and when I stop it you will see that it actually has calculated the macd indicator, so let’s exchange that and use rsi in the source code, I re-compile the code, restart the test and when I stop it this time you will see this is the rsi indicator.
Actually, I have created these import files for several expert advisors and indicators and once you have created one of these files here you can use them over and over again.
Let’s copy this one, that’s for the bollinger bands, I will paste the file inside of the import folder that I have created, let’s close this one, exchange the entry, click on compile and when I start a new test and stop it you will see the bollinger bands are calculated.
This is a very easy way to code something once and re-use it again and again, and in this little video you have learned how to include external source code files and you have coded it yourself with a few lines of mql4 code.