# Three ways to control MT4 from your own code

> MetaTrader 4 has no official API for traders. Here are the three real ways to get one in 2026, and what a hosted MT4 REST API looks like in practice.

Source: https://tickwire.io/blog/metatrader-4-api/

Tickwire blog, published 2026-11-03. General information, not investment advice.

MetaTrader 4 has no official API for traders. To control an MT4 account from your own code in 2026 you have three options: write an MQL4 program that runs inside the terminal and talks to the outside, ask a broker for server access (which brokers keep for themselves), or use a hosted MT4 REST API that runs the terminal for you. Tickwire is the third kind: it runs a real MT4 terminal for your account in the cloud and gives you REST and WebSocket endpoints for it, the same ones it uses for MT5.

This post explains each route, what the hosted route looks like in code, and the few things MT4 cannot do on any route.

## Why MT4 has no API of its own

MT4 was built as a desktop terminal. Its programming language, MQL4, runs inside that terminal. There is no official library you can import from Python or Node.js, and no official web API.

MT5 is a little different. It has an official Python package, but that package only runs on Windows, next to an open terminal. MT4 does not even have that.

So every "MT4 API" you find is built by someone on top of the terminal or the broker's server.

## The three routes

| Route | Who it suits | What you run |
|---|---|---|
| An MQL4 program inside the terminal | People who want full control and can run Windows | A terminal on a PC or VPS, your MQL4 code, and your own server to talk to |
| Broker server access | Brokers | The broker's own servers. Traders cannot get this |
| A hosted MT4 REST API | Developers who want HTTP and JSON | Nothing. You call an endpoint |

### Route 1: an MQL4 program inside the terminal

You write MQL4 code that reads the account and sends orders, then make it talk to your app over a socket, a file or a web request. It works. It is also a lot of plumbing. You keep a Windows machine running, restart the terminal when it hangs, handle logins, and design your own way to know whether an order really went through.

### Route 2: broker server access

Brokers have server side tools that manage every account on their server. These are for running a brokerage. A trader with one or ten accounts at a broker will not get access, and these tools are not meant for placing your own trades.

### Route 3: a hosted MT4 REST API

A provider runs the terminal on its machines, logs in for you, and exposes the account over HTTP. You send JSON and get JSON back. This is what Tickwire does. Each account gets its own real terminal, so there is no shared login and no simulated data.

## What the hosted route looks like

You add an MT4 account the same way as an MT5 one. Set `"platform": "mt4"` and give the server name from the MT4 login dialog. Any broker works.

```bash
export TW=https://api.tickwire.io

curl -s -X POST "$TW/users/current/accounts" \
  -H "auth-token: $TW_KEY" \
  -H "transaction-id: $(openssl rand -hex 16)" \
  -H "content-type: application/json" \
  -d '{
    "name": "my mt4 demo",
    "platform": "mt4",
    "server": "YourBroker-Server",
    "login": "12345678",
    "password": "your-password",
    "magic": 1000
  }'
```

The broker password is write only. It is never returned by the API. Use the master password to trade, or the investor password if you only want to read.

Once the account is running, reads are plain GET calls:

```bash
curl -s "$TW/users/current/accounts/$ACC/account-information" -H "auth-token: $TW_KEY"
curl -s "$TW/users/current/accounts/$ACC/positions" -H "auth-token: $TW_KEY"
curl -s "$TW/users/current/accounts/$ACC/symbols/EURUSD/current-price" -H "auth-token: $TW_KEY"
```

An order is a POST with an idempotency key. If the network drops and you send it again with the same key, you get the first answer back instead of a second order.

```bash
curl -s -X POST "$TW/users/current/accounts/$ACC/trade" \
  -H "auth-token: $TW_KEY" \
  -H "Idempotency-Key: mt4-first-order-1" \
  -H "X-Actor: my-script" \
  -H "X-Reason: testing the MT4 API on a demo account" \
  -H "content-type: application/json" \
  -d '{"actionType": "ORDER_TYPE_BUY", "symbol": "EURUSD", "volume": 0.01}'
```

The answer carries an `outcome`. It is `applied` when the terminal confirmed the order, `rejected` when it was refused, and `unknown` when the result is not clear. On `unknown`, read positions and orders before you do anything else. Never send it again under a new key. The [quickstart](https://tickwire.io/docs/quickstart/) walks through the full flow.

If you want to try this before adding a real demo account, the free [sandbox](https://tickwire.io/docs/sandbox/) gives you a key and a connected account with no sign in and no card. Ask for MT4 with `{"platform": "mt4"}` in the signup body.

## One API for MT4 and MT5

The endpoints, fields and stream frames are the same on both platforms. A script written for MT5 reads an MT4 account with no changes, as long as it does not use a feature MT4 lacks. There are also terminal style routes under `/mt4/{id}/` next to `/mt5/{id}/`, and the [MCP server](https://tickwire.io/docs/guides/ai-agent/) works with MT4 too. For a tour of the reference pages, see the [MT4 API documentation guide](https://tickwire.io/blog/mt4-api-documentation-guide/).

To check what an account supports, ask it:

```bash
curl -s "$TW/users/current/accounts/$ACC/capabilities" -H "auth-token: $TW_KEY"
```

On MT4 the `features` block shows `marketDepth`, `historicalTicks`, `stopLimitOrders`, `nettingAccounts` and `orderCheck` as `false`, and `closeBy` as `"broker_dependent"`.

## What MT4 cannot do

MT4 is an older platform. These features are missing on every route, not only on Tickwire:

| Feature | MT4 |
|---|---|
| Market depth | Not available |
| Historical ticks | Not available. Live ticks are captured from the time you subscribe |
| Stop limit orders | Not available |
| Netting accounts | No. MT4 accounts are hedging only |
| Timeframes | 1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w, 1mn (MT5 has 21) |
| History | Closed orders, shown as deals and history orders |

When you call one of these on an MT4 account, Tickwire answers with `not_supported_on_mt4`. It never makes up data. On the trade route the answer is `200` with `outcome: "rejected"`, and nothing is sent to the broker. Read more in [MT4 vs MT5 for algo trading](https://tickwire.io/blog/mt4-vs-mt5-for-algo-trading/).

## Which route should you pick?

Pick the MQL4 route if you already run Windows, want your logic inside the terminal, and are happy to build the plumbing.

Pick a hosted API if you want to write in Python, Node.js or any language with HTTP, and you do not want to keep a terminal alive yourself. The [hosted terminal vs VPS](https://tickwire.io/blog/hosted-terminal-vs-vps/) post compares the two in more detail.

Either way, an API only moves orders. It does not make a strategy profitable. Test on a demo account first.

## What it costs

Tickwire's Starter plan is from $12 per account a month, with a 7 day trial. The sandbox is free. The [pricing page](https://tickwire.io/pricing/) has the full table, and the [MetaTrader 4 API](https://tickwire.io/mt4-api/) page has an overview.

## Frequently asked questions

### Does MetaTrader 4 have an official API?

No. MT4 has MQL4 for programs that run inside the terminal, but no official web API and no official Python package. Every MT4 API is built on top of the terminal or the broker's server.

### Can I use the MT4 API from Python?

Yes, with a hosted REST API. You send HTTP requests from Python with a library such as requests and get JSON back. You do not need Windows or a local terminal.

### Is the MT4 API the same as the MT5 API on Tickwire?

Yes. The endpoints and fields are the same. You pick the platform when you add the account. A few MT5 features, such as market depth, return not_supported_on_mt4 on an MT4 account.

### Which brokers work?

Any MT4 broker. You give the server name shown in the terminal's login dialog, your login and your password.

### Can I read an MT4 account without being able to trade?

Yes. Add the account with its investor password. The account can then be read but not traded. You can also use a read only API key.

### Will an API make my MT4 strategy profitable?

No. An API only connects your code to the account. Whether a strategy makes or loses money depends on the strategy and the market. Nothing here is investment advice.
