In this article you can will learn the foundation of MQL5 Data Types and their characteristics. If you want to build your own trading tools you need to know them!
Summary Table of MQL5 Data Types
Before we see the details of each type it is useful to have an overview of most of the MQL5 Data Types available.
| Data Type | Description | Size | Example |
|---|---|---|---|
int | Integer numbers | 4 bytes | int trades = 10; |
long | Long integer numbers | 8 bytes | long bigNumber = 1000000000; |
short | Short integer numbers | 2 bytes | short smallNumber = 32000; |
uchar | Unsigned character | 1 byte | uchar letter = 'B'; |
uint | Unsigned integer | 4 bytes | uint positiveNumber = 100; |
ulong | Unsigned long integer | 8 bytes | ulong largePositive = 10000000000; |
double | Floating-point numbers | 8 bytes | double price = 1.2345; |
float | Single-precision float | 4 bytes | float volume = 0.5f; |
bool | Boolean values | 1 byte | bool isActive = true; |
char | Single character | 1 byte | char symbol = 'A'; |
string | Text strings | Varies | string pair = "EURUSD"; |
color | RGB color values | 4 bytes | color red = clrRed; |
datetime | Date and time representation | 8 bytes | datetime now = TimeCurrent(); |
void | Represents no value | N/A | Used in function definitions |
enum | Enumeration type | Varies | enum OrderType { BUY, SELL }; |
Intro to MQL5 Data Types
If you are already a programmer you should be familiar with data types and MQL5 is not different.
If you are not a seasoned programmer, you need to know that when working with variables and constants and data in general, you will need to understand what type of data you are handling.
MQL5, the programming language for MetaTrader 5, provides a rich set of data types. These as essential to build efficient and reliable trading algorithms.
Understanding these types is fundamental to writing clean, error-free code. Let’s dive into the different MQL5 data types, their uses, and their characteristics.

Details of MQL5 Data Types
While you will find here many MQL5 Data Types available, you will find out that you will often use the same few data types.
int, double, string and bool will be likely the most used.
As you gain experience and start building more complex tools, you may also use other types, hence it is important to at least have a general idea of what is available.
int – Integer Numbers
The int data type is used for whole numbers, both positive and negative.
- Size: 4 bytes
- Range: -2,147,483,648 to 2,147,483,647
- Usage: Often used for loop counters, array indices, and trade quantities.
Example:
|
1 2 3 4 5 |
int ordersCount = 5; if (ordersCount > 0) { Print("You have open orders."); } |
long – Long Integer Numbers
The long type holds larger whole numbers than int.
- Size: 8 bytes
- Range: Much larger than
int - Usage: When very large numbers are needed.
Example:
|
1 2 3 |
long accountBalance = 1000000000; Print("Balance: ", accountBalance); |
short – Short Integer Numbers
The short type saves memory for small whole numbers.
- Size: 2 bytes
- Range: -32,768 to 32,767
- Usage: When memory efficiency matters.
Example:
|
1 2 |
short tradeVolume = 32000; Print("Volume: ", tradeVolume); |
uchar – Unsigned Character
The uchar stores small positive values.
- Size: 1 byte
- Range: 0 to 255
Example:
|
1 2 |
uchar letter = 'B'; Print("Letter: ", letter); |
uint – Unsigned Integer
Stores positive whole numbers.
- Size: 4 bytes
- Range: 0 to 4,294,967,295
Example:
|
1 2 |
uint trades = 100; Print("Trade count: ", trades); |
ulong – Unsigned Long Integer
Stores large positive numbers.
- Size: 8 bytes
Example:
|
1 2 |
ulong bigNumber = 10000000000; Print("Big number: ", bigNumber); |
double – Floating-Point Numbers
Essential for precise decimal calculations.
- Size: 8 bytes
- Precision: 15-16 decimal places
- Usage: often used for lot size, and prices
Example:
|
1 2 |
double bidPrice = SymbolInfoDouble("EURUSD", SYMBOL_BID); Print("Current bid price: ", bidPrice); |
float – Single-Precision Float
A less-precise alternative to double.
- Size: 4 bytes
Example:
|
1 2 |
float multiplier = 1.5f; Print("Multiplier: ", multiplier); |
bool – Boolean Values
For true or false states.
- Size: 1 byte
Example:
|
1 2 3 4 |
bool isTrading = true; if (isTrading) { Print("Trading is active."); } |
char – Single Character
Stores a single ASCII character.
- Size: 1 byte
Example:
|
1 2 |
char grade = 'A'; Print("Your grade: ", grade); |
string – Text Strings
Holds sequences of characters.
- Usage: will be used for logs, messages and graphical interfaces.
Example:
|
1 2 |
string pair = "GBPUSD"; Print("Selected pair: ", pair); |
color – RGB Color Values
Used for graphical objects, background colors, borders, font and text and similar.
You can find the full list of colors available in MQL5 in the Web Colors page.
Example:
|
1 2 |
color greenLine = clrGreen; ObjectSetInteger(0, "TrendLine", OBJPROP_COLOR, greenLine); |
datetime – Date and Time Representation
Stores timestamps.
- Usage: often used for dates, expiry, logs, records, duration, time keeping
Example:
|
1 2 |
datetime currentTime = TimeCurrent(); Print("Current time: ", TimeToString(currentTime)); |
void – Represents No Value
For functions with no return.
Example:
|
1 2 3 4 |
void PrintMessage(string message) { Print(message); } PrintMessage("Hello, MQL5!"); |
enum – Enumeration Type
The enum type is used to define a set of named integer constants. Enumerations make code more readable and maintainable by replacing magic numbers with meaningful names.
- Size: Varies (typically same as
int) - Usage: Defining states, types, or modes in a program.
Example:
|
1 2 3 4 5 6 7 8 9 10 |
enum OrderType { BUY, SELL, PENDING }; OrderType currentOrder = BUY; if (currentOrder == BUY) { Print("Placing a buy order"); } |
Conclusion
Understanding MQL5 data types is crucial for writing effective and optimized trading programs.
Each type serves a specific purpose, balancing memory usage, precision, and functionality.
By mastering these types, you lay the foundation for efficient and powerful algorithmic trading scripts.
For questions or support please Contact Us.