#Data Types?

We create programs by writing source code and in this source code we use many variables. Variables are human readable names and each of them links to certain data with certain type.

Here you can see all data types that can be used in MQL4 and MQL5 programs:

These are the most basic data types:

  • int - whole numbers. For example 1 or 2, or 34, or 875
  • double - floating numbers. For example 1.2345
  • bool - boolean, there are two possible values - true or false. True is like 1 and False is like 0

These are often compatible with each other, because they are all numeric by nature. The difference is only in the minimum and maximum value that a variable with such data type can take. But there is one data type that is kind a different:

  • string - text. In the code we always use double quotes like this: "This is my string"

#In The Source Code

Examples of how variables are defined in the source code:

  • int MyNumericVariable = 1;
  • double MyFloatingNumber = 1.2345;
  • bool MyBool = true;
  • string MyText = "Hello, World!";

#Enumerations

These are more complex data types and you can read about them here:

What you should know is that you can use Enumerations to define better looking input parameters of your robots. Let's take the Moving Average indicator as an example. This indicator has few input parameters - Period, Shift, Method and Apply to.

MetaTrader - Moving Average Inputs

The data type of the first two parameters is int - whole numbers. The last two parameters, however, have more interesting data types. Let's take Method for example, look at how many values it can take:

MetaTrader - Moving Average Inputs (Method)

That's because the type of the Method parameter is ENUM_MA_METHOD, which is a predefined enumeration. Predefined means that it exists in MQL4/MQL5, someone already defined it. This enumeration have 4 possible values:

  • Simple averaging, written in the code as the predefined variable MODE_SMA, which has a value of 0
  • Exponential averaging, written in the code as the predefined variable MODE_EMA, which has a value of 1
  • Smoothed averaging, written in the code as the predefined variable MODE_SMMA, which has a value of 2
  • Linear-weighted averaging, written in the code as the predefined variable MODE_LWMA, which has a value of 3

By now you should understand, that enumerations are just a way to define few possible integer values in the code. Or, a way to make drop-down menus in the input parameters of our robots. Sure, for the Method parameter we can simply use integer values from 0 to 3, but it's much easier if we know all the possible values and they are written in human readable format.

#In fxDreema

  • In Blocks - All input parameters in the settings window of each block are variables and they have certain data types
  • In Custom Indicators - All input parameters are global variables (in the indicator itself) and they have certain data types
  • Constants and Variables - All of them are global variables with certain data type