4 Common Data Types Used in Forex EA Programming

Now that we’ve covered the basic structure of a forex expert advisor, let’s delve into the main ingredients that you’ll be using in coming up with a coding recipe to make those yummy pips. In this part of my tutorial series on MQL programming, we’ll take a look at the common data types:

1. Integers

integer forex eaOh man, middle school third period math class flashback! If you paid close attention instead of secretly passing love notes to your cute seatmate then, you’d remember that an integer is just a fancy mathematical term for whole numbers. In other words, integers can be positive or negative numbers without decimals.

In coding, integer values are denoted by “int” followed by its variable name and value like so:

int Age = 35;

Integers can be used to keep track of the number of open and pending orders, the number of hourly candles, or the number of winning trades.

2. Real numbers

“What do you mean REAL numbers? Does this mean there are fake numbers?” Well, you might be interested to know that there are IMAGINARY numbers, but that’s a different (boring!) topic altogether.

Real numbers are basically those that have decimals or fractional parts such as 1.5, 0.7950, or 3.14159265359. This is denoted by “double” followed by its name and value:

double Height = 6.54;

This data type can be used to keep track of currency pair levels, differences between opening and closing prices, the average number of long orders opened, and many more.

3. Boolean values

Boo-what now? In case you haven’t encountered this term before, just remember that Boolean data types just indicate truth or falsehood. If your forex robot tells a lie, its nose will grow long like Pinocchio’s! Just kidding!

Boolean values are denoted by “bool” and can take the following values: true, TRUE, 1 if they indicate a true statement or false, FALSE, 0 if they indicate a false statement. These are typically used in situations where prices or indicators need to meet certain conditions before a trade signal is given. Sounds really useful, huh?

4. Strings

Nope, not referring to the orchestra section right here. In coding, strings refer to ASCII characters, which is geek-speak for text. This is denoted by “string” followed by the variable name and text inside double quotes like this:

string Title = “Trade History”

Next week we’ll focus more on the proper syntax for declaring and initializing variables under these different data types. Stay tuned!