Skip to content
All library documents

A Reusable MQL5 Template for Building Single-Symbol Trading Robots

Article MQL5 articles

Summary

This article presents a reusable MQL5 Expert Advisor framework for a single symbol and timeframe. Its purpose is to separate strategy rules from recurring platform tasks, including loading price history, detecting new bars, checking spreads, sizing positions, and managing orders. The framework centers on a virtual chart, a trading robot object that holds parameters and state, and initialization and cycle functions that coordinate their work. Strategy-specific entry and exit logic is meant to be added in a designated calculation method.

The main loop uses timer events during live operation and tick events in the Strategy Tester, with an initialization call followed by repeated simulation cycles that update market data, run the robot logic, and refresh the interface. The article also describes configurable lot sizing, stops and targets, averaging or martingale options, and a mode for holding losing positions until a time or exit condition is met. These are implementation features, not evidence of trading performance. The template is presented as a learning and development foundation; its example signal and risk options still need strategy-specific review and testing.

Key ideas

  • A reusable framework can keep signal rules separate from recurring execution and platform code.
  • The design divides work among a virtual chart, a robot object, and global event functions.
  • Live trading and Strategy Tester operation use different event triggers but share a simulation cycle.
  • The template includes configurable sizing, stop and target handling, and optional averaging or martingale behavior.
  • The article provides software architecture guidance rather than evidence that a strategy built on it will be profitable.

Tags

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