In this video we want to talk about the MQL4 template that is used to create a basic Expert Advisor and we also want to talk about the content inside of that template.
An Expert Advisor is an automated program that is able to do everything that humans also could do.
This is one of those Expert Advisors, its trading right now; it is able to open and close positions without any human interaction and to create one of those Expert Advisors you would click on this little icon here or press F4 on your keyboard.
This is the programming environment that comes with Metatrader 4 and MQL4 and to create a new Expert Advisor we can use the wizard, we just need to click on: “New/ Expert Advisor (template)” from template, now we click on “Continue”, I will call this version: “SimpleEATemplate”, click on “Continue”, “Continue” and “Finish”.
And here is our template! The upper part contains some information about the name of the template, the copyright and the website that we have provided in the process, these double slashes are comments, so everything that comes behind double slashes is ignored by the complier it’s just for us humans to make things more readable
Here we have some properties for the copyright, the link, the version and there is also a property called: “strict”. If you mark the property expression and hit the F1 key you will see the help file and it will explain that a property is additional and it’s a specific parameter.
For example “strict” means that the compiler should use the strict compilation mode, the copyright property would be used for the company name and so on.
Inside of the template you will find an “OnInit” and an “OnDeinit” and an “OnTick” function. These are built-in functions, let’s mark “OnInit”, press F1 and we learn that the “OnInit” function is used for initialization because it’s the first thing that is running as soon as we start our Expert Advisor.
“OnDeinit” is the function that will run before you close your Expert Advisor; you can use it to clean up before you close your Expert Advisor.
The most important function is the “OnTick” function because this one will run every time when a new tick for a symbol is received and that is always the case when the price changes.
You will find further functions like: “OnTimer” and “OnTester”, if you are interested just open the MQL4 reference by pressing F1.
For our simple example we can remove everything above the “OnTick” function because this one is the one that is most interesting, we can also remove the two comment lines here and everything between the two brackets here will be executed each time when the price changes.
Right now you could click on the “Compile” button here and you would already have a working version.
So far it doesn’t do very much; we are going to change that in the next few videos.
In this video you have learned how to create a new empty Expert Advisor that is created from a template and you have done it by generating a template with a few lines of MQL4.


SimpleEaTemplate1.mq4 – Downloaded 222 times – 1.35 KB