Expert Advisor Creation Expert Advisors are programs that allow automation of the analytical and trading processes in the MT4 platform. To create an Expert Advisor (or "Expert"), the expert editing program - MetaEditor - has to be opened from within the MT4 platform. To open the editor (see Figure 1):
|Figure 1 - There are several ways to open the MetaEditor.|
Any of these actions will open the Expert Creation Wizard. The Wizard can be used to create Expert Advisors, Custom Indicators, Scripts and DLLs. To create an Expert Advisor, select "Expert Advisor" and click "Next" to continue, as shown in Figure 2.
|Figure 2 - MT4\'s Expert Advisor Wizard is used to create Expert Advisors, Custom Indicators, Scripts and Libraries (DLLs).|
The "General Properties of the Expert Advisor" window appears. Here, traders must specify the:
To add a new parameter to the Inputs field, press the "Add" button. For each Parameter, the trader must specify the Name, Type and Initial Value, as shown in Figure 3. To delete a parameter, highlight the parameter and press "Delete." These become the Input Variables within the Expert. Once all the inputs have been listed, click "Finish" to continue.
|Figure 3 - Create the input variables by identifying Name, Type and Initial Value.|
A new window appears in the programming environment. The Expert's name appears at the top of the window, and the previously entered input parameters are listed near the top of the code, as shown in Figure 4.
|Figure 4 -The Expert name and inputs appear in the code window.|
From here, the Expert code can be entered into the window using the MQL4 programming language and syntax (see Figure 5).
Note: Specifics regarding programming are outside the scope of this tutorial; understanding programming logic and learning a specific language require significant effort. Traders can learn more about programming in the MQL4 environment by reading the MT4 Help Guides and participating in the active MQL4 community forums.
MQL4, like other proprietary languages, has a list of Reserved Words and Standard Constants that are used during programming. Examples of constants for trade operations, along with their descriptions, include:
|Figure 5 - part of the code for an Expert Advisor. Certain words have predefined uses; here, OP_SELL instructs the computer to sell if other criteria are met (if statements).|
Traders can find a MQL4 Reference in the Help tab of the Toolbox in the MetaEditor window. This Reference includes information that is helpful to beginner and experienced programmers including:
Expert Advisor Compiling
After the Expert development has been completed, it must be compiled in order to ensure that the code has been written in the proper format needed to run the Expert. To compile the Expert:
Once compiling has been initiated, an update appears in the Toolbox beneath the code in the MetaEditor window, as shown in Figure 6. An errors or warnings will be listed.
|Figure 6 - Successful compiling with zero errors and zero warnings.|
After successful compilation, the new Expert will appear in the Navigator - Expert Advisors window, as shown in Figure 7. If the Expert did not compile successfully, it will still appear but its icon will be gray and the Expert cannot be used.
|Figure 7 - The new Expert now appears in the Navigator-Expert Advisors window.|
Expert Advisor Setup
Before the Expert can be used, its parameters must be defined in the Terminal Settings window. To open the window:
|Figure 8 - Select the "Expert Advisors" tab in the Options window to define an Expert\'s parameters.|
The following settings are available in the "Expert Advisors" tab:
Once the selections have been made, click "OK" to close the window.
Expert Advisor Launch
A window appears with Common and Inputs tabs, as shown in Figure 9. Review the settings in each tab and make any necessary changes, and then click "OK" to attach the Expert to the active price chart.
|Figure 9 - Make any changes to the Common and Inputs tabs before attaching the Expert to the active price chart.|
The Expert will now be attached to the price chart. Its name will appear in the upper right-hand corner of the chart. The Expert's name will be followed by a smiley face, as shown in Figure 10, if live trading is enabled. Otherwise, the Expert's name will appear with a frowny face, a dagger after the name indicates that all experts are disabled.
|Figure 10 - An Expert with a smiley face indicates that live trading has been enabled.|
The Expert is now ready to begin analytical and trading functions.
Expert Advisor Shutdown
To shut down an Expert, it has to be removed from the chart. To remove an Expert, right-click on the active price chart, select "Expert Advisors" and then "Remove," as shown in Figure 11.
|Figure 11 - To remove an Expert, right-click the active price chart, select "Expert Advisors" from the drop-down menu, and then select "Remove."|
Notes About Expert Advisors