IntroductionHello dear reader! In this book, I will try to explain and show you how you can easily and quickly get the hang of the principles of creating Expert Advisors, working with indicators, etc. It is beginner-oriented and will not feature any difficult or abstruse examples. So the article may probably not be so inspiring and informative for those of you who already know how to program Expert Advisors.
Expert Advisor and Its StructureExpert Advisor is a program written in the MQL language that specifies conditions for doing the trade or keeping aside.
Basically, the structure of an EA can be made up of a great number of blocks but in order to make it easier to understand, I am going to give a very simple example generated by default in MetaEditor.
The entire EA can be visually divided into 4 parts each of which is responsible for a certain part of the work to be performed.
Parameter Block contains information for the terminal allowing it to handle the EA in a proper way. The most common parameters are the EA version, name of manufacturing company and a brief description. OnInit() Block gains control once the EA is loaded into the terminal. It can contain various data related to the initialization of the EA - declaring variables and arrays, getting indicator handles, etc. That is, this block does not have any functions that would be directly associated with trading. OnDeinit() Block acts as the inverse of the OnInit() Block. It is called when the EA completes its operation (EA/Terminal shutdown or unsuccessful initialization of an EA). One of the main functions of this block is deallocation of memory space occupied by the EA when it is no longer needed. In other words, it describes processes of deleting variables, arrays and indicator handles, etc. OnTick() Block is called every time the new information on the symbol (currency pair) is received from the server. It specifies conditions for doing the trade and functions of the trade itself.