Back to library
Library term·Algorithmic trading

OrderSend() vs OrderSendAsync(): Asynchronous Order Flow in MQL5

Blocking vs non-blocking trade requests in MetaTrader 5: latency, OnTradeTransaction reconciliation, and design patterns for multi-symbol EAs.

Authored by·Editorially reviewed
Onur Erkan Yıldız
Founder, Financial Engineer · CMB-licensed

Why the distinction matters

Retail quants often underestimate how much single-threaded blocking costs inside an OnTick handler. OrderSend() returns only after the trade server answers; during that window no other tick logic executes on that expert’s main thread. When you scale to multi-instrument hedging, baskets, or correlated grid unwinds, serialization becomes a hidden drag on time-to-risk-update.

OrderSendAsync() submits the request and relies on transaction events (OnTradeTransaction) for ground truth. Algorithmically, you are shifting from a synchronous remote procedure call mental model to event-sourced order lifecycle management.

Architectural trade-offs

Advantages

  • Lower tick blocking — keep reading quotes and maintaining state while requests are in flight.

  • Pipelining — issue several requests in rapid succession subject to broker throttles / symbol trade context rules.

  • Cleaner separation between intent (“close 40% exposure on EUR crosses”) and observed fills.
Costs
  • You must engineer pending request maps, idempotency, and timeouts for events that never arrive after reconnect.

  • Partial fills and requotes introduce eventually consistent bookkeeping — dangerous if position limits are enforced only synchronously after OrderSend.

Reconciliation blueprint

Maintain a keyed structure for intent tickets correlated with MetaTrader request identifiers when available. On each TRADE_TRANSACTION_DEAL_, update risk aggregates — not when you think* an order landed, but when the platform records a binding deal. Hedge accounts vs netting semantics differ; always align with account margin mode and fifo rules marketed to your geography.

For professional deployment, supplement with explicit maximum outstanding async count circuit breakers.

Finvestopia context

Finvestopia’s live stack emphasises low-latency tape integrity across instruments. Designing EAs with async pipelines mirrors how our backend isolates broadcast from execution feedback — minimise blocking on the hot path, validate on the event ledger.

Related entries

Educational content authored by our team — informational only, not investment advice.