In this video we want to talk about data types and what data types are.

In our case in this strategy test we see that the local time has a special format and whenever you calculate something it is important to choose the right type of data type, so let’s find out how to do that. 

We start by clicking on this little icon here or you can also press F4, now you should see the Metaeditor and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “SimpleDataTypes”, click on “Continue”, “Continue” and “Finish” now you can delete everything above the “OnTick” function and the two comment lines here.

Let’s start with the most obvious type of data and that is a text, in our case we use the data type: “string” to assign this text to a string variable that is called: “Text”, but you couldn’t use them to calculate anything. If you want to calculate anything you would need to use the right kind of value.

For example to get the balance value for our account we use a “double” type, “double” is a floating point type and by using the function “AccountInfoDouble” in combination with this expression here – it’s all uppercase – we should get the right value, so let’s see, we will use the “Comment” function to output the “Text” followed by the calculated value.

Let’s click on the “Compile” button here or press F7 and that should work without any errors and if that is the case you can click on a little icon here or press a F4 to go back to Metatrader.

In the last video we have learned how to use this Strategy Tester, so let’s click on: “File/ Strategy Tester”, here we pick the new file: “SimpleDataTypes” and start a new test, and now you should see the value is 100,000.0, let’s change that here, start another test and this time you will see the digits behind the dot and that is why we use “double” when we do anything with floating type values. 

You already know the “TimeLocal” function from the previous video and that will return a variable of the type “datetime”, so let’s create an output for this one, recompile the code, stop the previous test and start a new one and now you see the output is in a special kind of formatted value, so “datetime” is what we want to use whenever we need something with time and date.

For whole numbers you can use the “integer” type, in this case for the account number, we get it by using “AccountInfoInteger”, using this constant for account log in (ACCOUNT_LOGIN), let’s see how this looks like and here it is.

When you expect only true or false as a statement you use the “bool” type, so let’s see how the output for this one looks like, and now we see the output: “The value is: true”.

These have been a few common data types, if you click on “Help” or press F1 you should find the MQL5 Reference article about data types and you will learn that there are a few more types that you can use, complex data types are also possible.

I would suggest to write little test programs like this one because in this little video you learned how to output different data types directly on your chart and you have coded it yourself with a few lines of MQL5 code.