Skip to content
All library documents

Centralized Event Handling for Modular Expert Advisors

Article MQL5 articles

Summary

This article explains the event model and core classes of a reusable MetaTrader 5 trading engine. It proposes routing market and timer events through a centralized handler, so strategy logic can respond consistently to ticks, new bars, timers, and order-book changes. Because MetaTrader does not provide a dedicated new-bar event, the engine detects that condition itself by comparing bar times.

The CStrategy class combines event handling with configurable trading modes and methods for opening and managing long and short positions. It scans active positions, filters them by expert identifier, and dispatches them to the appropriate support logic. A CPosition abstraction supplies common operations such as closing a position or changing protective levels, with the stated aim of keeping strategy rules separate from platform-specific trading mechanics. The article is an architectural explanation rather than a performance study; it gives no evidence that the framework improves trading results, and readers implementing it still need to define their own strategy rules.

Key ideas

  • A centralized event model can bring system events and detected new-bar events into one strategy workflow.
  • Passing the event type to strategy methods lets them distinguish why they were called.
  • CStrategy coordinates event handling, trading modes, and position management for derived strategies.
  • A position abstraction standardizes actions such as closing trades and modifying protective levels.

Tags

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