First session using Expert Advisors!

Hi folks,

Your speaker today Coders’ Guru, One of Mars planet residents who have been decided to travel to the Earth when I heard about the great advantages of using MetaTrader Expert Advisors.

Unbelievable story huh? Ok this is a real one:

It was a full of traffic day, the trend going the expected direction and the pips fall down one after one from the sky. I have to stay in front of my terminal these hours to fill my pocket to the maximum gain I could make.

Suddenly, I found my little daughter crossing my room and shouting at me “Father, you promised me to teach me today how to set the chess board”. I promised here today? I don’t remember!

My wife entered the room and said to my daughter “don’t bother your father” I smiled “Your father always forgets his promises” I shocked “didn’t you promise me to go shopping together today?” I promised here today? I don’t remember!

Well, I have to use an expert advisor to automate my trade and to safe my family!

What is the expert advisor?

The expert advisor is a piece of code (Some of instructions you give to MetaTrader) written in a specific programming language called MetaQuotes Programming Language Version 4 (abbreviated to MQL4) compiled to a program which can stay in front of the terminal instead of you and automates your trades. It can analyze the chart as any indicator do plus it can at specific conditions to 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 talking to the new comers to 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 you maybe 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) that means you have the source code of the expert advisor.

Source code means you have the expert advisor as a piece of code that 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.

It requires converting this expert advisor to another format it understands, it the .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. This will produce a file name as same as the name of 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 to use expert advisor but unfortunately you can not open it in the text editor to view the source code (because it’s in binary format not text format like the mq4 files). 

Wait! You can't load the expert advisor to 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 is in the installing folder of MetaTrader.

If you not sure where is this folder just right click on the MetaTrader icon and select Properties from the context menu then click Find Target button (Figure 5). 

Congratulations! You can load the expert advisor to MetaTrader now and only now. 

Loading an expert advisor! 

You have the .ex4 version of the expert advisor and the expert advisor is located at /experts folder. Well, you are ready now to use the expert advisor.

You will find the name of the expert advisor in the MetaTrader Navigator window (Figure 6).

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 advisors that 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 (Figure 7), clicking View menu and choose Navigator or simply hit 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 prompt 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 have 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 that means the expert advisor is not enabled! 

Enabling the expert advisor: 

You have to tell MetaTrader to use expert advisor to automate your trade, you have to enable the expert advisor. 

From the toolbar of the MetaTrader you will find Expert Advisors check button (Figure 10). Check button means when you click it enables 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).