Skip to content

Start here

Connecting MetaTrader 5

How your MetaTrader 5 terminal connects to the trading core: what the MQL5 gateway sends, what it accepts, and why it holds no trading logic at all.

Last reviewed: 25 August 2026

What the gateway is

An Expert Advisor running on a MetaTrader 5 terminal, and nothing more ambitious than that. It has one job in each direction: push what the market and the account are doing out to the trading core, and carry order commands back into MT5.

It holds no strategy. It calculates no indicators, evaluates no risk, and never decides to open, close or resize anything on its own. That is a deliberate constraint rather than an unfinished feature: MQL5 is hard to test and runs on a Windows terminal that is harder to control than a supervised service, so every decision worth auditing was moved into the C++ core where it can be tested and versioned.

What crosses the connection

Messages exchanged between the terminal and the trading core
DirectionMessageWhen
Terminal → coreTick — symbol, bid, ask, timestampOn price movement
Terminal → coreAccount state — equity, balance, margin used and freeOn a timer, every few seconds
Terminal → coreExecution result — filled, rejected or partial, with the broker error codeImmediately on any trade transaction
Core → terminalOrder command — open, close or modify, with stop-loss and take-profitOnly after the risk engine has approved

Every message carries both a broker identifier and a customer identifier. That is what lets the core resolve a broker's own symbol naming back to a canonical instrument, and what guarantees one customer's positions can never be attributed to another.

One terminal per customer, one gateway per broker

Terminals are never shared between customers. Each customer gets their own MT5 terminal and their own gateway instance, provisioned when they connect a broker. If you connect more than one broker, each gets its own gateway with its own broker identifier.

Stop-loss and take-profit always rest at the broker

When an order command is executed, the stop-loss and take-profit are set on the broker's own order — not merely tracked in memory somewhere upstream.

Why this detail matters more than it sounds

It is the reason a connection failure is survivable. If the link between your terminal and the trading core drops, the gateway is under strict instructions to do nothing to your open positions — no closing, no adjusting, no guessing. What protects them in that window is the stop level already resting at the broker, which needs neither our software nor your internet connection to trigger.

A resting stop is not a guaranteed fill. In a fast or gapping market it becomes an order at the next available price, which may be worse than the level set. That is a property of the market, not of this system, and no software removes it.

Terminal settings that matter

  • Algorithmic trading must be enabled in the terminal. With it off, order commands arrive and cannot be executed.
  • DLL imports must be permitted for the gateway, which uses a messaging library to reach the core. MQL5 has no usable native transport of its own.
  • The terminal must stay running. Ticks are the heartbeat that position management runs on.

A terminal that is closed is not a paused system

Closing the terminal does not put your positions in a safe holding state. It stops the tick flow that trailing and break-even logic depend on, and leaves your positions protected only by the stop levels already at the broker. If you need to take a terminal down, treat any open position as unmanaged until it is back.

How to tell it is healthy

The console reports connection state and the age of the last tick per symbol. Stale data is not treated as a cosmetic problem: the risk engine rejects proposals on any symbol whose last tick is older than the freshness limit, so a silent feed produces rejections rather than trades at prices that may no longer exist.

If something looks wrong, Troubleshooting lists the failures that actually occur and what each one means.