MQL5 Program Structure, Preprocessor Directives, and Event Handlers
Summary
This tutorial explains the main parts of an MQL5 program and how they fit together. It covers preprocessing directives for defining macros, setting program properties, including files, importing functions, and compiling code conditionally. It then describes input variables, which users can configure before initialization, and global variables, which are available across program functions.
The article also introduces functions, classes, and event handlers, with examples of how program components are organized for different MQL5 program types. It names handlers such as initialization, tick, calculation, timer, trade, and testing events, and frames the sequence as a foundation for building scripts, indicators, and Expert Advisors. The material is a broad programming overview rather than a trading method or a complete reference; some sections are abbreviated in the supplied text, so details of function and handler behavior are limited.
Key ideas
- MQL5 preprocessing happens before compilation and supports macros, properties, includes, imports, and conditional compilation.
- Input variables expose configurable settings to users and are initialized before the program initialization handler.
- Global variables are declared outside functions and can be accessed throughout the program.
- Program type and purpose determine which event handlers are relevant.
- The guide provides an introductory structure, not a full reference for every language feature.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.