MetaTrader Library

Place orders from your MT4 or MT5 strategy into one or many accounts, using our ready-made library.

MT4 / MT5 + Desktop ClientBridge connectionAbout 10 minutesBroker independent
In short

Install our MetaTrader library to automate orders from your MT4 or MT5 strategy. Install it from the AutoTrader Desktop Client (or manually), include autotrader.mqh in your strategy, and call functions like placeOrder. The library works with both MT4 and MT5 and can trade in multiple accounts.

What it is

The MetaTrader library lets you place orders from your MT4 or MT5 strategy into single or multiple accounts. It is fully compatible with both MT4 and MT5.

How it connects

MetaTrader is a bridge client. Your strategy writes order requests to files on your computer. The Desktop Client, running locally, reads those files and sends the real instructions on to AutoTrader Web and your broker. So you need the Desktop Client installed and running in MONITORING state.

How clients reach your brokerTwo paths
DirectPython · Java · C# · HTTP REST
Your code
on your PC or a server
secure web
AutoTrader Web
the platform
Your broker
any supported broker
BridgeExcel · AmiBroker · MetaTrader
Your tool
spreadsheet / charts
request file
Desktop Client
runs on your PC
secure web
AutoTrader Web
then your broker

Before you begin

Have these ready first:

  • The AutoTrader Desktop Client, installed and running in MONITORING state.
  • MetaTrader (MT4 or MT5) installed on your computer.
  • An AutoTrader Web account, with your API key set in the Desktop Client.
  • At least one broker account added as a pseudo account.

If you face any problem, try the manual installation steps below, or contact the support team for help.

Migration

If you are migrating from our previous generation AutoTrader system, note that the API functions have changed. The most notable change is the addition of the Pseudo Account, an extra parameter in all functions.

Installation

  1. Install the AutoTrader Desktop client.
  2. Start the Desktop client.
  3. Go to the Settings tab.
  4. Click the MetaTrader Library Install button.
  5. The system automatically tries to locate your MetaTrader folders and installs the library.

Manual Installation

If the automatic installation fails, you can install the library manually.

  • Download the library.
  • Open it with WinZip or WinRar and extract the files.
  • Copy the files from the Include folder to your MetaTrader’s Include folder.
    • A sample path is given below. You need to find the correct path on your own computer.
    • C:\Users\<windows_user>\AppData\Roaming\MetaQuotes\Terminal\F762D69EEEA9B4430D7F17C82167C844\MQL5\Include
    • If you are using MT4, the folder above will be MQL4.

Client Setup

  1. Install and open the AutoTrader Desktop client.
  2. Go to its Settings tab and change the communication path as given below. Find the similar path on your own computer.
    1. C:\Users\<windows_user>\AppData\Roaming\MetaQuotes\Terminal\Common\Files\autotrader
  3. Note: The desktop client must be running and in MONITORING state for the APIs to work.

Integration

Once the library is installed, the next step is to integrate it into your trading strategy.

Code

As with any other library, to use its functions in your strategy you must include it at the top of your strategy code:

#include <autotrader.mqh>

That’s about it. Now you are ready to use the API functions provided in the library.

Regular Order

string id = placeOrder(AT_ACCOUNT,
	AT_EXCHANGE, AT_SYMBOL, SELL, LIMIT, INTRADAY, 1,
	192.44, 0.0, true);

Bracket Order

string id = placeBracketOrder(AT_ACCOUNT,
	AT_EXCHANGE, AT_SYMBOL, BUY, LIMIT, 1,
	192, 0.0, 1, 1, 0, true);

Cover Order

string id = placeCoverOrder(AT_ACCOUNT,
	AT_EXCHANGE, AT_SYMBOL, BUY, LIMIT, 1,
	192, 190.5, true);

Cancel Order

string orderId = placeOrder(AT_ACCOUNT,
	AT_EXCHANGE, AT_SYMBOL, SELL, LIMIT, INTRADAY, 1,
	192.44, 0.0, true);

// You can even store the orderId
// in a static variable

// Somewhere later in your code,
// when you want to cancel this order

cancelOrder(AT_ACCOUNT, orderId);

API Functions

All API functions are available inside Include\autotrader.mqh. Do NOT modify this file.

Note: A detailed explanation, with examples, is provided for each function in the API documentation.

Parameters

The library defines certain parameters that you can set in the chart parameters window. They are listed below.

ParameterDescription
AT_ACCOUNTPseudo account
AT_EXCHANGEInstrument’s exchange
AT_SYMBOLInstrument’s symbol
AT_PRODUCT_TYPEDefault product type
AT_QUANTITYDefault quantity
AT_PRICE_PRECISIONPrice precision for rounding
AT_DEBUGPrint additional logs
AT_AVOID_REPEAT_ORDER_DELAYAvoid repeat order delay (in seconds)

A broker independent instrument’s Exchange & Symbol can be looked up using this global instruments search tool.

MetaTrader Chart Parameters

MetaTrader Chart Parameters – Derivatives

Logs

Here is a sample of the logs that print information about the order being placed.

MetaTrader Logs

MetaTrader Logs

Trading in Multiple Accounts

There are two approaches to trade into multiple accounts. You can read about them in Trading Strategies For Multiple Accounts.

Approach 1: One Strategy Instance Per Account

To trade in multiple accounts, you run multiple charts or scanners, with one chart or scanner per account.

Approach 2: One Strategy for All Accounts

All the API functions take the account number as a parameter. So instead of using just a single AT_ACCOUNT chart parameter, you can hard-code the account in your code. Here is a sample:

// Place order in ACC1
placeOrder("ACC1", AT_EXCHANGE, AT_SYMBOL, BUY, MARKET,
	AT_PRODUCT_TYPE, AT_QUANTITY, 0, defaultTriggerPrice(), false);

// Place order in ACC2
placeOrder("ACC2", AT_EXCHANGE, AT_SYMBOL, BUY, MARKET,
	AT_PRODUCT_TYPE, 0, buyPrice, defaultTriggerPrice(), false);

Next steps

Was this page helpful?

Last updated 19 June 2026