Modular Expert Advisor Design with Independent Trading Components
Summary
This article explains how to organize a MetaTrader Expert Advisor as a set of independent modules coordinated through lifecycle handlers. It recommends initializing components in OnInit, placing strategy decisions and module communication in OnTick, and cleaning up in OnDeinit. The example EA sells after a bearish prior candle, while separate components handle trade execution, parameters, position snapshots, strategy logic, and dynamic strategy switching.
Centralizing interactions makes modules easier to add, remove, debug, and reuse. The article develops the design from a simple example toward a hierarchy in which a strategy can depend on initialized services, while a panel can switch the active strategy. It relates the approach to Observer and Facade design ideas, while noting that modules sometimes need exceptions to remain fully independent. The examples focus on software structure rather than evaluating a profitable trading method; they provide no backtest results or evidence that the sample candle signal has an edge.
Key ideas
- Initialize reusable components in the startup handler and coordinate their use through the tick handler.
- Keep trading logic, execution, parameters, and position tracking in separate modules.
- Centralized module communication can simplify debugging and future changes.
- A strategy object can be replaced dynamically to change the Expert Advisor's operating logic.
- The sample bearish-candle entry illustrates architecture, not a validated trading edge.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.