Contact

How to enable, launch and customize Expert Advisors (robots) on your MetaTrader 4 platform?

Nick
September 19, 2019
by Nick Alexander,

Article Recap

Learn how to create and use expert advisors (EAs) in MetaTrader 4

Expert Advisors (EAs), also known as robots, are supplementary programs that can be activated or added to the MT4 platform to help you automate the trading process and analysis. With the use of algorithms, expert advisors examine and analyse financial markets, searching for the best trading prospects. EAs are often used to automatically place and close trades, especially when it comes to multiple positions. They can send notifications to the trader or directly activate trading conditions like trailing stops and limits.

Once you know the basics of trading in MetaTrader 4, you are ready to explore the possibilities that EAs offer. Learning how to activate and customize expert advisors with this tutorial will make trading more efficient. If you are using MetaTrader 5, please read our MT5 article.

 

This MetaTrader 4 step-by-step tutorial will teach you:

  • How to enable and launch expert advisors in MT4;
  • How to add and remove EAs from MT4 charts;
  • How to create and edit expert advisors in MetaEditor;
  • How to download expert advisors from the Market;

How to enable expert advisors in MT4

Before you start using and expanding your EAs, first you need to make sure that they are enabled and configured according to your trading account. To do that, use the “Auto Trading” button in the toolbar. A single click enables/disables the automated trading for your MT4 platform.

EAs-MT4-1

 

To enable EAs and to configure them, select “Options” from the main menu “Tools”.

EAs-MT4-2

 

From the Options window that pops up, go to the “Expert Advisors” tab and make sure “Allow automated trading” is ticked.

EAs-MT4-3

This enables the use of Expert Advisors and other scripts. Please note that even when this setting is deactivated, scripts and Expert Advisors may still seem active, but they will not be able to execute any trades. When in disabled mode, the analytic capabilities of the EAs can still be tested in real-time mode (they can be also tested with your history data). Enabling and disabling automated trading from the main menu or the toolbar effects the entire MT4 terminal, overwriting the settings of every individual Expert Advisor. To activate a particular EA, both the general auto trade settings and the settings of the EA itself need to be enabled.

From the Options window, you can set under what conditions auto trading is enabled. If you don’t want your EAs to remain activated when you switch to another account, tick the first option: “Disable automated trading when the account has been changed”. Similarly, you can disable it when you change your MT4 profile by selecting “Disable automated trading when the profile has been changed”. This option is particularly important since profiles usually contain a lot of chart data (including expert advisors attached to it). When this is ticked, you prevent EAs from another profile to be instantly activated and to start placing trades. Just as described, the last option “Disable automated trading when the charts symbol or period has been changed” allows you to deactivate EAs when you make key configurations to your charts: change of time period and symbol.

EAs-MT4-4

In this tab there are two more major functionalities that can be enabled:

  • “Allow DLL imports”, which concerns expert advisors that work with external DLLs (dynamic-links libraries). If this is deactivated, none of your expert advisors will be able to use DLLs. The MetaTrader platform recommends disabling this functionality when working with unreliable experts. DLLs allow developers to share data in order to update functionalities without the need to re-link and re-compile applications.
  • “Allow WebRequest for listed URL” – WebRequest is MQL4 functionality allowing the transfer of information to websites via GET and POST requests. To enable this in your MetaTrader 4, you need to also list the URLs of trusted websites that can use this function. By default, this is deactivated, due to safety concerns.

EAs-MT4-5

How to launch expert advisors in MT4

After you have enabled and configured the main auto trading parameters in MT4, you are ready to launch any individual expert advisor you want to use.

To do so, go to the Navigator panel and expand the Expert Advisors (EAs) group, which contains all expert advisors available on your platform. Open the context menu of the expert you want to activate and select “Attach to a chart” to add it to the chart active at the moment. You can also simply drag the EA to the chart.
EAs-MT4-6

When you confirm the activation, the window for configuring the EA will pop up. Although many of the EAs are different, most of their settings are similar. The expert window contains the tabs “About”, “Common” and “Inputs”. The “Common” tab allows you to select what positions the EA will be applied to: long, short or both. Here you can also set alerts and tick “Allow live trading” in order to activate the EA (note that EAs must be also enabled from the general MT4 settings; the same is valid for DLL settings).

“Allow import of external experts” controls the calling of functions from third-party EAs. Some experts may not work if this remains disabled.

Some expert advisors may also have the option to “Allow modification of Signals settings” – this enables the subscription to Signals (a subscription to a provider offering trading signals, providing the trader with suggested trades that they can copy in their own trading) and modifying them.

EAs-MT4-7

 

The ”Inputs” tab displays the parameters of the expert advisor with values that can be modified with a double-click of the mouse.

Here, you can also utilise prearranged sets of inputs. To import sets just click the “Load” button and use “Save” to keep your own values. Click “Reset” to go back to the default settings.

EAs-MT4-8

Note that just one expert advisor can be added to a chart. If second expert is attached, it will replace the first one on the chart.

The expert will be activated the minute the Properties window is closed. Once an EA is activated, it will execute when a tick comes in. During execution, the Properties window cannot be open, unless it’s while the EA is being restarted or in-between operations.

You can confirm that an expert is attached to a chart if you see its name and emoticon in the upper right corner of the chart. If live trading is disabled for this expert, the letter “L” will be on the place of the emoticon. You can click on the icon to open the Properties window. The symbol for dagger tells you that all EAs are disabled.

EAs-MT4-9

How to remove expert advisors from MT4 charts

As we have already established, EAs are removed when they are replaced with another robot or when you switch to a different chart or template, depending on your general auto trading settings. However, to directly close an expert, the trader needs to remove it from the chart. To do that, open the chart context menu, select “Expert Advisors” and then “Remove”.

When the platform is shut down, EAs stop working as well.

EAs-MT4-10

 

At the same time, the deletion of an expert from the Navigator doesn’t shut down the EA itself, if it is already attached to the chart. Deactivating experts in the general platform settings (in the Tools menu) does not disable experts entirely. This action prevents each expert from executing its start() function (immediately after a new tick comes), while the init() function (executed after the start of the terminal or after any change to accounts, charts and EA parameters including changing chart period, recompiling code, changing EA inputs or switching accounts) remains active.

 

Strategy Testing

MetaTrader 4 allows traders to test expert advisors before using them. This gives you the chance to test their efficiency under different market conditions and based on history data.

Select “Strategy tester” in the main “View” menu to open the Tester panel that enables you to test various strategies and to optimize the parameters of the EAs you want to use.

EAs-MT4-11

 

While adjusting the parameters of the EA, you can evaluate its trading efficiency and find out when profitability is at its highest.

EAs-MT4-12

 

To learn more about strategy testing in MetaTrader 4, please read EightCap’s “Optimize and Test Trading Strategies in MetaTrader 4?” tutorial.

 

How to create expert advisors in MetaEditor

How to use MetaEditor

As a platform MetaTrader 4 is very flexible and it allows various customizations, including the creation of EAs from scratch with the help of the MetaQuotes 4 (MQL4) language and the MetaEditor, which is installed automatically within your MT4 package.

The MetaEditor is component of the MT4 client terminal that’s utilised for the creation and editing of experts, indicators, libraries and other scripts written in MQL4.

To open the editing program, go to the Navigator panel, and click on top of the Expert Advisors group to open the context menu. Select the “Create in MetaEditor” option to open it.

EAs-MT4-13

 

Optionally, you can open the editor from the main “Tools” menu, from the MetaEditor button in the toolbar or by pressing F4.

EAs-MT4-14

 

How to create expert advisors with MQL4 in the MetaEditor

With the MetaEditor open, you can start editing experts from your list or make a new one. Click the “Create New” button in the toolbar to start a new project and tick “Expert advisor”.

EAs-MT4-15

 

On the next step enter the name of the expert in development, the name of the developer (individual or company), link to the website of the developer and parameters needed (a list of inputs for the EA). Select “Next”.

EAs-MT4-16

 

The following windows contain settings on events. The events here signify the specific moments, in which you can execute the custom EA code. Initially, you can leave these settings as they are by default.

EAs-MT4-17

 

The expert you have just set up will open in the editor. Now you are ready to start writing your own code.

EAs-MT4-18

 

To compile the file after you’re finished with development, go to the “File” main menu and select “Compile”

EAs-MT4-19

 

or click on the “Compile” button in the toolbar (F5). This will create an executable program file with the .EX4 extension.

EAs-MT4-20

 

Your list of every compiled expert is updated in the Navigator panel on the left. If the file isn’t compiled properly, the icon of the EA appears grey.

EAs-MT4-21

 

How to edit expert advisors with MQL4 in the MetaEditor

With the MetaEditor you can easily edit any expert you have at your disposal by selecting “Modify” from the context menu of the EA. Note that once the changes are made, the file needs to be recompiled.

EAs-MT4-22

 

How to download expert advisors from the Market

Instead of writing your own experts, you can browse through thousands of paid and free EAs from the official MetaTrader website at https://www.mql5.com/

Go to the “Market” menu and filter your results for MetaTrader 4 and EAs. Here you can buy or download expert advisors that are not available on your MT4 platform.

EAs-MT4-23

 

Open the page of the robot and download it.

EAs-MT4-24

 

Once downloaded, the EA will be automatically installed and visible in the Terminal panel, in the “Market” tab.

EAs-MT4-25

 

The expert will also show up in the Navigator panel. Using its context menu, you can activate and modify it.

EAs-MT4-26

 

Instead of searching in the MQL5 website, you can simply open the context menu of the experts in the Navigator panel and select “Online library”. A list of available EA robots will open in the Terminal. Clicking on any of the experts will redirect you to its own page on the site. From there, the steps are the same as previously described.

EAs-MT4-27

Good trading from Eightcap.
All times are AEDT.