MQL5 PROGRAMMING – ABOUT DATA TYPES

video
play-sharp-fill
In this video we would like to take a look at the topic of data types. Depending on what kind of value you want to calculate, you need different data types to get the right result. And we want to take a look at how to do this. To do this, we click on this small symbol in the Metatrader or press the F4 key. That calls then here the Meta Editor. And here we click on File, New, Expert Advisor from template, Next. I assign here once the name SimpleDataTypes, click on Next, Next and Finish. And now everything above the OnTick function can be deleted here. Also the two comment lines are removed. And we start with the simplest data type. That would be the text. In MQL5 this is a so-called string variable. It gets a name. In our case text. And we assign a value to it. This is a string of text. You could also write numbers here, but they would be treated as text and you couldn’t count on them. There are other data types for numbers, for example the data type Double. This is the correct data type for floating point values. In our case we want to determine the balance, that is, the gross balance in our account. For this purpose we use the function AccountInfoDouble. And pass this constant Account_Balance to it here. You can recognize these reserved constants for certain values by the fact that they are displayed in red color and in capital letters. To be able to see something, we now use the Comment command and let us output the text followed by the balance. Click here on compile. And if that worked without any errors, we click on this little icon up here or press F4 to return to the Meta Trader. And in the Meta Trader we learned how to use the strategy tester in the last video. So we click on View, Strategy Tester, select our newly created program SimpleDataTypes here. And start our test. And now the ACTUAL value is displayed up here followed by the determined value. In this case, I deliberately entered 100,000 dollars and 12 cents as the account size. As you can see, the decimal places are also output. We have already learned about the TimeLocal function. It returns the type DateTime, for example to calculate the local time. If we compile this once and start a new test, we get an output in this format here. For integer numbers there is the datatype integer or here abbreviated int. For example, our account number has no decimal places and therefore we get an integer value for the account number via AccountInfoInteger with the constant AccountLogIn, compile this here again. Start a new test. And this time our account number is displayed here as an integer. If you want to display a true or false value, you use so-called boolean variables. They can only take the value true for true or false for false. Let’s output this as well. Then here on our chart the value IS true. If you call the help with the F1 key once and search for data types, you will find this article here, which introduces further data types. This video was only about the most common ones. There are also compound data types for structures or classes. Why don’t you make a small program to find out what other data types you want to use. Because in this short video you learned how to use different data types to display values on your chart. And you programmed it yourself with these few lines here in MQL5.