Discussing the article: "Designing a Unified Order Execution Gateway Class in MQL5"

 

Check out the new article: Designing a Unified Order Execution Gateway Class in MQL5.

This class provides one point of contact for trade operations in MQL5. It rounds and clamps lot sizes, validates SL/TP against the broker's minimum distance, resolves a compatible filling policy, and applies bounded retries for transient retcodes. Calls return a structured CGatewayResult instead of raw retcodes, simplifying error handling and maintenance across strategies.

Open almost any moderately complex Expert Advisor and you will find OrderSend() called from several different places: one call site for the entry signal, another for a scale-in, another buried inside a trailing stop routine, maybe a fourth inside a recovery or grid module. Each of these call sites tends to grow its own retry logic, its own lot-size rounding, its own idea of what counts as an acceptable stop distance. The code works, mostly, until the broker changes its minimum lot step, or a new error code starts showing up in the Experts log and needs to be added to a retry list — at which point the fix has to be found and applied in every location that touches OrderSend(), and it is easy to miss one.

This is not a hypothetical problem. It is the normal trajectory of an EA codebase that started small and grew. The execution logic is not wrong, exactly — it is just scattered, which makes it hard to test in isolation and hard to change with confidence.

This article builds CExecutionGateway as a single point of contact for trade operations in an EA. The gateway normalizes lot sizes and validates SL/TP against broker constraints. It also resolves the supported filling policy, retries transient retcodes, checks slippage, and returns a structured result. By the end you will have four reusable include files, a thin demo EA that wires them together, and a script that verifies the normalization and validation logic with a set of synthetic assertions.

Architectural diagram

Author: Ushana Kevin Iorkumbul

 

How does CExecutionGateway in this article differ from the class with the same name in the article "OrderSend Retries and Circuit Breaker in MQL5"?

  • If this class performs the same task, why did you re-develop it instead of using existing code?
  • If this class performs a different task, why did you create a name collision?

How can I integrate the developments from both of your articles into a single EA? Do you personally use both developments or only one of them, and why?