MetaTrader Library
Place orders from your MT4 or MT5 strategy into one or many accounts, using our ready-made library.
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.
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
- Install the AutoTrader Desktop client.
- Start the Desktop client.
- Go to the Settings tab.
- Click the MetaTrader Library Install button.
- 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
- Install and open the AutoTrader Desktop client.
- Go to its Settings tab and change the communication path as given below. Find the similar path on your own computer.
- C:\Users\<windows_user>\AppData\Roaming\MetaQuotes\Terminal\Common\Files\autotrader
- 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.
| Parameter | Description |
|---|---|
AT_ACCOUNT | Pseudo account |
AT_EXCHANGE | Instrument’s exchange |
AT_SYMBOL | Instrument’s symbol |
AT_PRODUCT_TYPE | Default product type |
AT_QUANTITY | Default quantity |
AT_PRICE_PRECISION | Price precision for rounding |
AT_DEBUG | Print additional logs |
AT_AVOID_REPEAT_ORDER_DELAY | Avoid 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
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
Thanks for the feedback. Still stuck? Contact support.
Last updated 19 June 2026