Setup Guide

How to Connect MetaTrader 5 to an AI Trading App

2025-01-124 min readMetaSync AI

Almost every trader who tries to automate MetaTrader 5 hits the same wall in the first hour. They search for an "MT5 API", find a documentation page that assumes a broker partnership, and conclude that automation is closed to them. It is not. The confusion comes from three completely different things being called the same name, and once you separate them the path forward becomes short and cheap.

The three ways software can reach a MetaTrader 5 account

The first is a broker API. This is a private interface that a broker licenses to selected partners — Exness, Vantage and XM all run one. It lets an approved company open accounts, move money and place trades on behalf of clients. It requires a commercial agreement, compliance review and, usually, a legal entity. If you are an individual trader or a small app developer, this door is shut, and that is fine because you do not need it.

The second is a managed gateway. Companies such as MetaApi run real MetaTrader terminals on their own servers and expose a REST and WebSocket layer in front of them. You send JSON, they send orders to the broker. It works with any broker, needs no agreement, and is billed monthly per account. The trade-off is that your credentials live on someone else's machine and you pay for the convenience.

The third, and the one this guide focuses on, is a bridge EA. MetaTrader 5 can run Expert Advisors — programs written in MQL5 that execute inside the terminal with full trading permissions. An EA can open an HTTP connection to your own server, ask "is there anything to do?", and act on the answer. That single capability turns the terminal into an API you control. No broker permission is involved because the broker only ever sees a normal EA trading a normal account.

Why the bridge EA approach wins for most people

It costs nothing per account, it works on every broker without exception, and your login and password never leave your own machine — the EA authenticates outward with a licence key instead of you handing credentials inward. It also survives broker-side changes, because the terminal is doing the trading exactly as it always has. The only requirement is that the terminal is running, which for a trader is already true during market hours.

The architecture is small enough to describe in one sentence: your app writes a signal to a database, the EA polls an endpoint every few seconds, receives the signal, and executes it with the symbol, direction, lot size, stop loss and take profit you specified. Execution results flow back through a callback endpoint so your app knows the trade actually filled and at what price.

Step 1 — Get the EA onto a chart

Download the bridge EA from your app and copy the .ex5 file into the terminal's MQL5/Experts folder. In MetaTrader 5, open File → Open Data Folder, drop the file in, then right-click Expert Advisors in the Navigator and press Refresh. Drag the EA onto a chart of the symbol you intend to trade.

In the dialog that appears, enable Allow Algo Trading, then set three inputs: the base URL of your server, the licence key from your app profile, and the poll interval in seconds. Three seconds is a good default — fast enough for intraday setups, light enough that the terminal is not hammering the network.

Step 2 — Allow the connection

MetaTrader blocks outbound HTTP by default. Go to Tools → Options → Expert Advisors and tick Allow WebRequest for listed URL, then add your server's origin — for example https://www.metasync-ai.com. Without this the EA logs error 4060 and nothing else happens, which is the single most common reason a bridge "does not work".

Finally, confirm the Algo Trading button in the toolbar is green. The EA's smiley face in the top-right corner of the chart should be smiling, not frowning.

Step 3 — Verify the handshake

Open the Experts tab at the bottom of the terminal. A healthy bridge prints a line like connected, polling every 3s within a few seconds. In your app, the terminal status indicator should flip to online and start showing live prices, because the EA also pushes symbol quotes back up on the same connection.

If the status stays offline, check the three usual suspects in order: the WebRequest allow-list, a trailing slash in the base URL, and an expired licence key. Ninety percent of failed first connections are one of those.

Step 4 — Send a test trade

Before letting any strategy run, place a single manual signal from your app with a tiny lot size on a demo account. Watch it appear in the terminal's Trade tab within one poll cycle. Then check that the app received the execution callback with a real ticket number. That round trip — signal out, ticket back — is the whole system proven end to end.

What this unlocks

Once the bridge is live, everything else is software. An AI model can parse a sentence like "buy gold if it reclaims 2,340 with a stop under the Asian low" into a structured rule. A vision model can read a chart screenshot and return levels. A scheduler can fire setups at the London open. None of that requires a broker relationship, because the EA is the only thing that ever touches the account.

If you would rather not run a terminal at all, the managed gateway route is the alternative — same app, different transport. The important thing is to stop looking for a broker API you cannot have, and start with the bridge you can set up this afternoon.

Put this into practice

MetaSync AI connects MetaTrader 5 and cTrader accounts, generates MQL5 Expert Advisors and executes strategies from one console.

Open the terminal   More articles →