Building a Moving Average Crossover Expert Advisor in MQL
Summary
This beginner guide introduces the structure of an MQL Expert Advisor and shows how it can obtain indicator values and send trades. It explains the roles of initialization, shutdown, and tick-processing functions, then describes indicator handles, buffers, and time-series indexing. The practical example uses a moving average and closing prices to identify crossover conditions, closes an existing position when the opposite signal appears, and opens a position in the new direction.
The article also distinguishes orders, executed trades, and open positions, and demonstrates using standard trading-library functions to manage requests. It reports a quick historical test on EURUSD hourly data using opening prices only, but explicitly says the example is not designed as a profitable system and notes that its drawdowns are visible. The result is an introductory programming demonstration, not evidence of a validated strategy; no robust performance analysis or risk controls are presented.
Key ideas
- An Expert Advisor separates setup, cleanup, and per-tick trading logic into distinct event functions.
- Indicator handles and buffers let an EA access calculated values such as moving averages.
- The example opens or reverses a position when the moving average crosses the closing price.
- Orders are requests, trades are executions, and positions represent current exposure.
- The reported quick test has noticeable drawdowns and is presented as a programming example rather than a proven strategy.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.