Skip to content
All library documents

Designing a Modular Order System for Trading Replay

Article MQL5 articles

Summary

This article begins a series on building an order system for a MetaTrader 5 replay and simulation environment. Its initial design goal is to let the same expert advisor run in a tester and on a live or demo account, while making the simulated server behavior transparent to the user. The installment focuses on class structure and encapsulation: it removes the terminal class from the inheritance chain and passes it to dependent classes as a pointer, limiting which components can access terminal information.

The article illustrates the approach through changes to the mouse and study classes, including pointer validation and error reporting. It also introduces a basic orders class and discusses how pending order types depend on whether charts use bid-ask or last prices. This is a software architecture discussion rather than a trading strategy or a completed execution system; the order system is explicitly incomplete, and later installments are needed to cover interaction with the trading server and simulation behavior.

Key ideas

  • Passing the terminal object as a parameter helps preserve encapsulation between expert advisor components.
  • The mouse and study classes validate terminal pointers and report invalid pointers through user errors.
  • A replay system aims to let one expert advisor build work in both simulated and real trading environments.
  • Pending order type selection depends partly on whether the chart is based on bid-ask or last prices.
  • This installment establishes a basic class structure and leaves the full order system for later parts.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.