Using Expert Advisors


Hi folks,

Well, I have to use an Expert Advisor to automate my trade.

What is the Expert Advisor?

The Expert Advisor is a piece of code, or some instructions that you give to MetaTrader, written in a specific programming language called MetaQuotes Programming Language Version 4 (abbreviated to MQL4) that is compiled to a program which stays in front of the terminal and automates your trades for you. It can analyze the chart as any indicator does, as well as at specific conditions, open, modify and close the trading orders.
The Expert Advisor can do anything you can do, except one only thing, it can't do a mistake!
Our task today is to talk to newcomers of MetaTrader who want to know how to use the Expert Advisors in MetaTrader.


Expert Advisors format:

Logically, to use the Expert Advisor, you have to have it. There are two formats of Expert Advisors that you may already have:

.mq4 format:


If you have the Expert Advisor in xxx.mq4 format (where the xxx is the Expert Advisor name followed by dot then the mq4 extension), then you have the source code of the Expert Advisor. Source code means you have the Expert Advisor as a piece of code, written in MQL4. You can open this file in any text editor and read it, but you can't use it in MetaTrader yet. Why? That's because, MetaTrader can't load this kind of Expert Advisors, and requires an extra step before loading it. You need to convert this Expert Advisor to another format that MetaTrader can easily understand, .ex4 format.

Converting .mq4 to .ex4:

MetaTrader can load only the Expert Advisors which have the .ex4 extension. The ex4 files are the executable version of the mq4. (Executable means they are not in text format anymore, but they are in binary format). To convert the mq4 to ex4, you have to do the following:

1. Open the mq4 file in the MetaEditor (Figure 1). MetaEditor is a program shipped with MetaTrader enabling you to write your own Expert Advisors, and to convert them to ex4 format. To open MetaEditor, you can double-click the .mq4 file, or you can click the Start button, then Program Files (All Programs in windows XP) and search for MetaTrader menu, then choose MetaEditor (Figure 2). But, if you opened the MetaEditor from the Program Files, you have to click File menu in MetaEditor, then Open command (Figure 3) to browse for the .mq4 file you want to convert to .ex4.


Figure 1 - MetaEditor


Figure 2 - Program Files


Figure 3 - Open command

2. After loading the mq4 file into MetaTrader, go to File menu and choose Compile command (Figure 4) or hit F5.


Figure 4 - Compile command

3. It will produce a filename that is the same name as the mq4 file, but with .ex4 file extension. This file will be created in the same path of the .mq4.

.ex4 format:

This is the executable version of the Expert Advisor. It's ready for use in MetaTrader, but unfortunately, you can not open it in the text editor to view the source code as it is now in binary format and not text format like the mq4 files. Wait! You can't load the Expert Advisor into MetaTrader yet. MetaTrader require extra step before loading the Expert advisor, which I consider it a shortage in this great program. You have to copy the .ex4 file to the /experts folder. You will find the /experts folder in the installation folder of MetaTrader. If you not sure where this folder is located, just right click on the MetaTrader icon and select Properties from the context menu, then click Find Target button.
Congratulations! You can load the Expert Advisor into MetaTrader now and only now. Loading an Expert Advisor! Now, that you have the .ex4 version of the Expert Advisor, and the Expert Advisor is located at /experts folder. You are now ready to use the Expert Advisor.
You will find the name of the Expert Advisor in the MetaTrader Navigator window.
As you can see in figure 6, the Navigator window is divided to tree of lists; the list which we interest in is Expert Advisors list. In this list, you will find all the Expert Advisorsthat are in your /experts folder and, of course, which are already compiled to .ex4 format.
Note: If you don't see the Navigator window in your terminal or you closed it, you can bring it back by clicking the Navigator button in the MetaTrader toolbar, just by clicking the View menu, and choosing Navigator or simply hitting the CTRL+N hotkeys.
To load the Expert Advisor from the navigator window, you can do one of two things:
1. Drag the Expert Advisor to the chart you want it to automate. Dragging means selecting the Expert Advisor from the Navigator window, and holding the left button of the mouse while moving the mouse to the chart, then releasing the left button on the chart.
2. Double-click the Expert Advisor you want to attach to the chart. But, be sure you have activated the chart you want to work with. Activating the chart means simply clicking it.
When you load the Expert Advisor to the chart, you will be prompted with the Expert Advisor input windows (Figure 8).
In this window, you can input the required data to the Expert Advisor. For example: Take Profit value, Stop Loss value and Lots value.
Note: You will get the details of all the inputs of every Expert Advisor from the creator of the Expert Advisor, or from the forum you downloaded the Expert Advisor from.
You can change the inputs of the Expert Advisor, or you can leave the default values you see in the input window. After setting the inputs of the Expert Advisor, you need to click OK.
If you are a lucky person, you will see the name of the Expert Advisor on the right upper corner of the chart with a fascinating smile beside it (Figure 9). If you didn't find this smile icon, it means that the Expert Advisor is not enabled!

Enabling the Expert Advisor:

You have to tell MetaTrader to use Expert Advisor to automate your trade by enabling the Expert Advisor. From the toolbar of the MetaTrader, you will find Expert Advisors check button (Figure 10). Check button means you can click it to enable the Expert Advisors, and goes to pressed figure, and when you click it again; it disables the Expert Advisor and goes to un-pressed figure (Figure 11).
Note: When you disable the Expert Advisor the smile icon goes to "x" icon (Figure 12).

Do You Like this Article?