MetaTrader 5 Help

Expert Advisors and Custom Indicators

Expert Advisors and Custom Indicators

Two broad categories can be singled out among automated trading applications: trading robots and indicators. Applications of the first type are designed for performing trading operations, and the second type programs are used for analyzing prices and identifying patterns in price changes. Indicators can be used directly in trading robots forming a complete automated trading system.

How to Run a Trading Robot or an Indicator

To start an Expert Advisor, attach it to a chart. The easiest way is to double-click on an Expert Advisor in the Navigator window or drag'n'drop it to a chart.

Starting a trading robot on a chart

This will bring up the Expert Advisor Properties window. Click OK to start the Expert Advisors on the chart. If an Expert Advisor has been successfully started, its name and icon Auto Trading enabled appear in the upper right corner of the chart.

If the icon is Auto Trading disabled, the Expert Advisor is not allowed to perform trading operations. Enable automated trading in the Expert Advisor settings, as well as in the trading platform options.

  • Only one Expert Advisor can run on one chart. If you start another Expert Advisor on the same chart, the first one is removed.
  • The number of indicators applied on one chart is not limited.

Application Setup before Start

A window of application properties opens before it is started on a chart.

Common

The "Common" tab contains information about the application: name, version, copyright, the software developing company name (two last parameters can be represented as links to the corresponding web page) and description.

If a license is required for an Expert Advisor (for example, it is purchased or downloaded from the Market), the appropriate license details (expiration date, demo) are displayed here.

Individual parameters of the Expert Advisor start are set up at the bottom of the window:

  • Allow modification of Signals settings — this option allows an MQL5 application to subscribe and unsubscribe from Signals, as well as edit signal settings. The functions for accessing the database of Signals from an MQL5 application enable you to perform your own analysis of the quality of signals, dynamically manage the subscription and adjust risks. More details about the signal managing functions are available in the MQL5 Reference.
  • Allow Auto Trading — this option limits the trading activities of Expert Advisors. This limitation can be useful when testing analytical capabilities of Expert Advisors in the real-time mode (not to be confused with backtesting). Note that even if this option is enabled, the autotrading for the Expert Advisor may be disabled in the common settings of the platform.

Common parameters for all Expert Advisors are specified in the trading platform settings.

Input Parameters of Trading Robots and Indicators

An application can have input parameters. They allow you to control the behavior of the application making its use more flexible. An application may have no input parameters if a developer has not provided them.

Input parameters

How to modify application parameters

To modify a parameter, double-click on it and enter a new value.

How to use parameter presets

You can use the "Save" button to save the current set of parameters and the "Load" button to load a previously saved set. Sets of input parameters are stored in the /Presets folder of the trading platform.

How to restore default settings

To restore the default settings, click "Reset".

Already attached Expert Advisors can be individually configured. However, the Expert Advisor properties window cannot be opened during the current execution. This can only be done in periods between the Start() function calls. In this case an Expert Advisor will not be started until its parameters window is closed. If input parameters of an Expert Advisors have been changed, the EA is re-initialized with new input parameters after the "OK" button is pressed.

Programs Using External Functions (DLL)

The "Dependencies" tab appears if the Expert Advisor uses the import of functions from other EX5 or DLL files. Use of external DLLs can extend the functionality of the program. However, it is potentially dangerous. These functions should be allowed only for trusted applications.

Dependencies

Files used by the Expert Advisor are displayed as a tree-like list. The green icons indicate calls of functions from MQL5 programs, and the red icons indicate calls of functions within DLLs.

An option for enabling/disabling DLLs is available at the top of the tab:

  • Allow DLL imports — Expert Advisors can use DLLs to extend their functionality. If this option is enabled, such libraries can be used without any restrictions. If an MQL5 application uses a DLL, but its import is prohibited (this option is disabled), then the "OK" button is not displayed in the application start window.

Do not enable the "Allow use DLL imports" option if you are not sure that launching the application is safe. Applications obtained from unknown sources may cause damage through the use of third-party DLLs.

How to Control Expert Advisor Trading

The possibility of automated trading can be controlled at the trading platform level or separately for every trading robot.

Button "Auto Trading Enabled AutoTrading" on the toolbar (and a similar option in Options — Expert Advisors) enables/disables automated trading in the platform. If you turn it off, automated trading is disabled for all Expert Advisors even if you enable automated trading individually in the Expert Advisors settings. If you enable it, the Expert Advisors is allowed to trade, unless automated trading is individually disabled in the Expert Advisor parameters.

Control over Expert Advisor trading

Automated trading permissions can be conveniently managed for individual Expert Advisors from the Navigator window, rather than in their parameters. In the Navigator window, the list of all running Expert Advisors is displayed for a connected account. In addition to the Expert Advisor name, a chart on which the EA is running is specified in the list. An icon indicates whether the EA is allowed to trade.

Expert Advisors running on the current account

The context menu contains commands for enabling or disabling automated trading for any of the Expert Advisors, as well as for viewing its properties or removing it from the chart.

Which Platform Settings Affect Automated Trading?

Settings affecting automated trading are available on the Expert Advisors tab of the platform options.

Expert Advisors

The following settings are available:

  • Allow Auto Trading — this option allows or prohibits trading using Expert Advisors and scripts. If it is disabled, scripts and Expert Advisors can work, but are not able to trade. This limitation can be useful for testing the analytical capabilities of an Expert Advisor in the real-time mode (not to be confused with testing on history data).
    The option enables/disables automated trading for the entire platform. If you disable it, no Expert Advisor will be allowed to trade, even if you enable automated trading individually in the Expert Advisor settings. If you enable it, the Expert Advisors will be allowed to trade, unless automated trading is individually disabled in the Expert Advisor parameters.
  • Disable automated trading when switching accounts — this option represents a protective mechanism disabling trading by Expert Advisors and scripts when the account is changed. It is useful, for example, when switching from a demo account to a real one.
  • Disable automated trading when switching profiles — a large amount of information about the current settings of all charts in the workspace is stored in profiles. Particularly, profiles contain information about Expert Advisors attached. Expert Advisors included into the profile will start working with the arrival of a new tick. Enable this option to prevent trading by Expert Advisors when changing the profile.
  • Disable automated trading when switching chart symbols or period — if this option is enabled, then when the period or symbol of a chart is changed, the Expert Advisor attached to it is automatically prohibited from trading.
  • Allow DLL imports (potentially dangerous, enable only for trusted applications) — to extend functionality, mql5 applications can use DLLs. This option allows determining a default value for the "Allow DLL imports" parameter used during start of applications. It is recommended to disable import when working with unknown Expert Advisors.
  • Allow WebRequest for listed URL — the WebRequest() function in MQL5 is used for receiving and sending information to websites using GET and POST requests. To allow an MQL5 application to send such requests, enable this option and manually explicitly specify the URLs of trusted websites. For security reasons, the option is disabled by default.
    To delete an address from the trusted list, select it and press "Delete".

Quick Access to Frequently Used Programs

For quick access to frequently used programs, use "Favorites" and hotkeys.

Select a trading robot, an indicator or a script and add it to your Favorites using the context menu. All of your favorite programs are displayed on a separate tab of the Navigator and can be easily accessed.

For a quick start on a chart, any program can be assigned a key shortcut. This can be done through the context menu of the Navigator window.

Adding programs to Favorites and assigning hotkeys

In the above example, keys "Alt+1" are set for a script. Once they are pressed, the script is instantly launched on the current open chart.