Experimental · Live verification pending

Native MT4/MT5 Connector

Speak the broker's wire protocol directly. No MetaTrader terminal, no Expert Advisor, no bridge process — a .NET library that logs in, streams ticks and trades on MT4 and MT5 from your own application.

Status & roadmap

Why native

The terminal-plus-EA route works, but it puts a GUI application, a chart and an EA between your strategy and the broker. The native connector removes that chain: one process, one socket per account, deterministic startup, and tick latency limited by the network — not by a terminal's message loop.

Path comparison
Terminal + EANative connector
Processes per accountTerminal + EA + appApp only
StartupTerminal launch, chart, EA attach, loginSocket connect + protocol login
Tick pathBroker → terminal → EA → TCP → appBroker → app
Headless / VPSNeeds a desktop sessionRuns as a service
Failure surfaceTerminal stalls, EA errors, chart stateSocket and session state, fully logged

Session flow

01 · CONNECT

Resolve & dial

The trade server is resolved from the broker server name and connected over TCP. MT4 and MT5 share one session abstraction.

02 · LOGIN

Protocol handshake

Native authentication per platform — MT5's encrypted login exchange, MT4's key-hardening handshake on modern server builds.

03 · SYNC

Account download

Symbols, groups, account state and open trades stream in after login, so the session starts consistent with the broker.

04 · STREAM & TRADE

Ticks and orders

Bit-packed MT5 tick records and MT4 quote packets decode into one quote model; trade requests, results and order updates flow on the same session.

Session, liveone socket per accountticks 0
Your app.NET library
Broker serverMT4 / MT5 wire protocol
ConnectLoginSync accountStream ticksTrade

Capabilities

Protocol coverageimplemented from the documented wire formats
AreaMT5MT4
Login & session keysEncrypted handshake, session AESXOR-chain login, key hardening (build ≥1010)
Tick streamBit-packed tick recordsQuote packets, session-key encrypted
Symbols & accountSymbol/group download, account stateSymbol records, account polling
TradingTrade requests, results, trades pumpOrder transactions, results, order updates
Order typesMarket, limit, stop, stop-limit; FOK/IOC policiesMarket, limit, stop; expiration handling with GTC fallback

The connector powers TwoLeg's native connection route: platform, login, password and server in the Connections UI, password DPAPI-encrypted in config, fast-feed capable.

Status, honestly

What is done

Both native sessions (MT4 and MT5), the shared resolver and limit-order layer, engine/config/UI wiring in TwoLeg, and the test suite are complete.

What remains

Live demo-account verification against real broker servers. Until that passes, the native route is flagged experimental in TwoLeg and the EA route remains the supported path.

The connector implements the broker protocols for interoperability with accounts you own. Use it only with your own accounts and within your broker's terms. Broker servers can change protocol details; the connector is maintained against current server builds.