Skip to content
All library documents

MQL5 Expert Advisor Fundamentals: Orders, Deals, Positions, and Events

Article MQL5 articles

Summary

This tutorial introduces the structure and basic operation of MetaTrader 5 Expert Advisors. It explains the roles of the initialization, shutdown, and tick handlers, and distinguishes orders (trade requests), deals (executions), and positions (resulting exposure). It also describes how netting and hedging account modes affect positions, and surveys event handlers for trade updates, timers, chart activity, and other terminal events.

The article develops two teaching examples: one EA places pending orders without indicators, while another uses a built-in moving average and trades at market. The examples are intended to demonstrate programming concepts, not serve as live strategies. The author cautions that the simpler code lacks robust request and server-response error handling, and that even the more validated example is not production-ready. Readers should treat the article as an introduction to EA structure and trade-operation concepts; strategy quality and operational safeguards require further work.

Key ideas

  • An Expert Advisor commonly initializes in OnInit, runs trading logic in OnTick, and cleans up in OnDeinit.
  • An order is a request, a deal is its execution, and a position represents resulting exposure.
  • Netting accounts consolidate trades into one position per symbol, while hedging accounts can hold multiple positions.
  • MetaTrader provides event handlers for trade updates, timers, chart interactions, and other events.
  • The sample EAs teach programming fundamentals and lack the safeguards needed for dependable live trading.

Tags

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