MQL4 Functions
Overview
Functions are used to write code for sub-tasks, implementing stepwise refinement. A function definition consists of a header and a body.
Function Definition
**Header**: Includes return value type, function name (identifier), and formal parameters.
**Body**: Contains the instructions enclosed in braces {}.Parameters
Maximum of 64 parameters per function.Function Prototype
Declaration of a function, specifying return type, identifier, and argument types.
Enables strict type checking and implicit typecasting during calls.
Used in classes for code readability.
A function definition must exactly match its declaration.
Every declared function must be defined.Return Operator
Returns the value of an expression, converted to the function's result type.
**Returnable types**: Simple types, simple structures, object pointers.
**Non-returnable types**: Arrays, class objects, variables of compound structure type.
For functions returning no value, use the void type.Default Parameter Values
Parameters can have default values defined by constants.
If any parameter has a default value, all subsequent parameters must also have default values.Related Concepts
Function Call
Passing Parameters
Function Overloading
Operation Overloading
External Functions
Exporting Functions
Event Handling Functions
Overload
Virtual Functions
Polymorphism