MetaTrader Library

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

MT4 / MT5Direct connectionAbout 5 minutesBroker independent
In short

Download the MetaTrader library from your AutoTrader Web account, extract it into your MetaTrader data folder, allow our address in MetaTrader's options, and include autotrader-http.mqh in your strategy. Your API key is already inside the download. 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 works with MetaTrader 5, and with MetaTrader 4 from build 600.

How it connects

MetaTrader talks to AutoTrader Web directly, over the internet. There is no second program to install and nothing that has to stay running in the background.

How your orders reach your brokerNothing else to install
DirectExcel · AmiBroker · MetaTrader · Python · Java · C# · HTTP REST
Your code or tool
on your PC or a server
secure web
AutoTrader Web
the platform
Your broker
any supported broker

Before you begin

Have these ready first:

  • MetaTrader installed on your computer — MT5, or MT4 build 600 or newer.
  • An AutoTrader Web account.
  • At least one broker account added as a pseudo account.

If you face any problem, contact the support team for help.

Installation

  1. Sign in to your account at webx.stocksdeveloper.in
  2. Go to Tools → Library
  3. Click Download on the MetaTrader card, and enter your AutoTrader password when asked
  4. Save the zip file
  5. In MetaTrader, open File → Open Data Folder
  6. Extract the zip into the MQL5 folder — MQL4 if you are on MetaTrader 4

The download already has your API key inside it. That is why the page asks for your password before it gives you the file.

Keep this file to yourself. Anyone who has it can place orders in your accounts. Do not e-mail it, and never attach it to a support request or a forum post.

Allow our address in MetaTrader

This step is not optional. MetaTrader refuses to contact any address that is not on its own allowed list, and it does so silently — your strategy runs, and no order is ever sent.

  1. In MetaTrader, open Tools → Options
  2. Go to the Expert Advisors tab
  3. Tick Allow WebRequest for listed URL
  4. Add this address:
https://api.stocksdeveloper.in
  1. Click OK

If you skip this, every request fails with error 4014. The library says so in plain words in the Experts tab the first time it happens.

Two rules about where your strategy runs

  • Use an Expert Advisor or a Script, not a custom indicator. MetaTrader does not allow web requests from an indicator.
  • The Strategy Tester cannot make web requests. A back-test therefore places no orders and reads no portfolio. That is the safe outcome — a back-test can never send real orders by mistake.

The library checks both and tells you once, in the Experts tab, rather than failing quietly on every call.

Where your key lives

Your key sits in one file: Include\autotrader-http-config.mqh. If you ever need to change it, edit that file and recompile your strategy.

The same file holds a few optional settings, such as how long the library re-uses portfolio data before asking again, and a switch to print every request and reply while you are setting things up.

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.

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-http.mqh>

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

It is worth calling autoTraderReady() once in OnInit. It checks that your key is set and that this program is allowed to make web requests, and it prints exactly what is missing:

int OnInit()
{
	if(!autoTraderReady()) {
		return(INIT_FAILED);
	}

	return(INIT_SUCCEEDED);
}

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);

What placeOrder gives you back

placeOrder waits for your broker’s answer and returns your broker’s own order id. It is the same id you see in your broker order book, and it is what you pass to getOrderStatus, modifyOrder and cancelOrder.

There are three possible answers, and it is worth handling all three:

string orderId = placeOrder(AT_ACCOUNT,
	AT_EXCHANGE, AT_SYMBOL, BUY, MARKET, INTRADAY, 1,
	0, 0, true);

if(orderId == AT_UNCONFIRMED) {
	// The order reached your broker and your broker did not confirm it.
	// It may be live. Do NOT send it again -- check your order book.
	Print("Order sent but not confirmed. Check the order book.");
} else if(orderId == "") {
	// The order was not placed. Safe to try again if you want to.
	Print("Order was not placed.");
} else {
	// Placed. This is your broker's order id.
	Print("Order placed: ", orderId);
}

The middle case is rare, but it is the one that matters. If you treat a blank answer and an unconfirmed answer the same way, a strategy can place the same order twice.

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 variable of your own

// 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-http-api.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

The library prints what it is doing in the Experts tab. To see every request and reply, set AT_HTTP_DEBUG to true in Include\autotrader-http-config.mqh. It never prints your API key. Turn it off again once things are working — it is noisy.

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);

Portfolio summary functions

The portfolio summary functions — getPortfolioMtm, getPortfolioPnl, and the position and order counts — are not part of this library. Use the position and order functions instead. For example, add up getPositionMtm for the positions you care about.

Holdings

The holdings functions now work. In the older library they always returned a blank value, because the library looked for your symbol in the wrong place. Nothing in your strategy needs to change — getHoldingQuantity, getHoldingAvgPrice and the rest simply return real numbers now.

Frequently asked questions

My orders do nothing and the log shows error 4014. What is wrong?

MetaTrader is blocking the request. Open Tools, then Options, then Expert Advisors, tick 'Allow WebRequest for listed URL', and add https://api.stocksdeveloper.in to the list. Nothing leaves MetaTrader until you do this.

Can I use the library in a custom indicator?

No. MetaTrader does not allow web requests from an indicator. Put your strategy in an Expert Advisor or a Script. The library tells you this once in the Experts tab if you get it wrong.

Why does nothing happen in the Strategy Tester?

The Strategy Tester cannot make web requests, so a back-test places no orders and reads no portfolio. This is deliberate — it means a back-test can never send real orders by mistake.

Next steps

Was this page helpful?

Last updated 6 September 2026