Forex Expert Advisor and Its Structure
Fig. 1. The main EA blocks
- 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.
Fig. 2. Example of a new document generated by default in MetaEditor
What we can see here is as follows:
- the first five lines (lines 1 through 5) represent comments containing the name of the EA (file name), the name of the manufacturing company and its website. You can write here anything you like. This text will not be seen anywhere and can even be skipped. The information it contains only targets the developer;
- the next 3 lines (lines 6 through 8) represent the Parameter Block. This information can be observed when starting the EA in the terminal;
- it is followed by the OnInit() function (lines 12 through 19). This is the OnInit() Block. This function does not get any parameters but returns (although it may as well not) the initialization code;
- the OnDeinit(const int reason) function goes next (lines 22 through 26). This is the OnDeinit() Block. It has one parameter that specifies the EA shutdown reason.
If the EA initialization is unsuccessful, this function receives a relevant code as a parameter; - the last function is OnTick() (lines 30 through 34). This is the earlier described OnTick() Block. This block can be said to be the "brains" of the EA as it comprises all functions in charge of trades.
Post a Comment