Building an MQL5 Trend EA with CTrade, Moving Averages, and ATR
Summary
The article demonstrates how to combine three MQL5 Standard Library classes in a trend-following Expert Advisor: CTrade for order execution, CiMA for fast and slow moving averages, and CiATR for volatility measurement. The example uses the moving averages to determine direction, ATR to set a dynamic stop distance and support position sizing, and a pullback condition to identify entries. It also outlines the indicator lifecycle, broker-aware volume normalization, execution checks, logging, and safeguards such as position caps and daily loss limits.
The document provides a worked EA design and recommends validating it with realistic Strategy Tester settings, out-of-sample or walk-forward checks, and conservative optimization. It does not present performance results demonstrating that the strategy is profitable. Its value is chiefly in illustrating implementation structure and risk controls; the proposed indicators and parameters remain choices to test for each market and setup.
Key ideas
- CTrade, CiMA, and CiATR can divide execution, trend detection, and volatility tasks in an Expert Advisor.
- A fast and slow moving-average comparison supplies a directional filter.
- ATR can inform stop distance and risk-based position sizing.
- Indicator values and trade requests need validation and clear failure handling.
- Backtests and parameter optimization require realistic costs and out-of-sample checks.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.