MQL5 Data Types

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!

Learning MetaTrader MQL5 Data Types

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 TypeDescriptionSizeExample
intInteger numbers4 bytesint trades = 10;
longLong integer numbers8 byteslong bigNumber = 1000000000;
shortShort integer numbers2 bytesshort smallNumber = 32000;
ucharUnsigned character1 byteuchar letter = 'B';
uintUnsigned integer4 bytesuint positiveNumber = 100;
ulongUnsigned long integer8 bytesulong largePositive = 10000000000;
doubleFloating-point numbers8 bytesdouble price = 1.2345;
floatSingle-precision float4 bytesfloat volume = 0.5f;
boolBoolean values1 bytebool isActive = true;
charSingle character1 bytechar symbol = 'A';
stringText stringsVariesstring pair = "EURUSD";
colorRGB color values4 bytescolor red = clrRed;
datetimeDate and time representation8 bytesdatetime now = TimeCurrent();
voidRepresents no valueN/AUsed in function definitions
enumEnumeration typeVariesenum 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.

Metatrader-MT5-MQL5-Data-Types-1

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:

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:

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:

uchar – Unsigned Character

The uchar stores small positive values.

  • Size: 1 byte
  • Range: 0 to 255

Example:

uint – Unsigned Integer

Stores positive whole numbers.

  • Size: 4 bytes
  • Range: 0 to 4,294,967,295

Example:

ulong – Unsigned Long Integer

Stores large positive numbers.

  • Size: 8 bytes

Example:

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:

float – Single-Precision Float

A less-precise alternative to double.

  • Size: 4 bytes

Example:

bool – Boolean Values

For true or false states.

  • Size: 1 byte

Example:

char – Single Character

Stores a single ASCII character.

  • Size: 1 byte

Example:

string – Text Strings

Holds sequences of characters.

  • Usage: will be used for logs, messages and graphical interfaces.

Example:

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:

datetime – Date and Time Representation

Stores timestamps.

  • Usage: often used for dates, expiry, logs, records, duration, time keeping

Example:

void – Represents No Value

For functions with no return.

Example:

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:

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.

MQL4 vs MQL5 Differences and Technical Insights

MQL5 Variables… Building Blocks Of Programs

Leave a Comment