MQL5 is a high-level programming language used for developing custom indicators, expert advisors (EAs), and other automated trading strategies for the MetaTrader 5 trading platform. Here are some key features of the MQL5 language:
- Object-Oriented Programming: MQL5 is an object-oriented language, which means that it is based on the concept of objects that contain both data and methods. This allows for easier and more efficient programming, as well as better organization and reuse of code.
- Integrated Development Environment: MQL5 comes with an integrated development environment (IDE) that includes a code editor, compiler, and debugger. This makes it easy to write and test code directly within the MetaTrader 5 platform.
- Extensive Library: MQL5 has an extensive library of built-in functions and indicators that can be used to develop trading strategies. Additionally, there are many third-party libraries available that can be integrated into MQL5 programs.
- Event-Driven Programming: MQL5 uses an event-driven programming model, which means that programs are executed in response to specific events, such as price changes, order executions, or timer events.
- Multi-Threading: MQL5 allows for multi-threaded programming, which means that multiple threads can be created to execute different parts of a program simultaneously. This can be useful for optimizing performance and managing complex trading strategies.
- Support for Multiple Data Types: MQL5 supports a wide range of data types, including integers, floating-point numbers, strings, and arrays. Additionally, it has built-in support for working with financial data, such as price and volume data.
Here's a simple example of an MQL5 program that calculates the moving average of a currency pair and prints the result to the terminal window:
// --- input parameters
input int Period = 20; // Period of the moving average
input ENUM_APPLIED_PRICE PriceType = PRICE_CLOSE; // Applied price type
// --- global variables
double MovingAverage; // Moving average value
// --- initialization function
int OnInit()
{
// Initialize the MovingAverage variable
MovingAverage = 0.0;
return(INIT_SUCCEEDED);
}
// --- main function
void OnTick()
{
// Calculate the moving average
MovingAverage = iMA(_Symbol, 0, Period, 0, PriceType, MODE_SMA, 0);
// Print the result to the terminal window
Print("Moving Average: ", MovingAverage);
}


