What is mql4 based on
Do not forget about the case! Then open the brackets and write parameters using commas. In our case parameters are of a string type. Like in any instruction, put a semicolon at the end. It shows how the code and results are bound:. Of course, it is all ok. But how can we show variables of other types?
Easily — make a mental note:. As you have already guessed, MQL4 is designed so, that when we try to add another number type to a line, it automatically transfers numbers into lines and combines them.
It is a really wonderful property! You can do such operations with string variables also:. Now you know how to draw different data using MessageBox function. But what is the interest of showing the results of simple mathematic operations?
Do not be afraid. It is very easy. Suppose you want to remember five prices. What should we do? Well, we can do this:. We get five variables, which have one data type and describe one parameter — price. We can go another way, using an array. An array is a set of variables, which differ in indexes, but have one name. This is how we declare an array from five elements:.
In our case: array type — double, name — price, number of elements — 5. We can perform any operations with the array elements, like with common variables. Actually, elements of the array are common variables:.
We simply enumerate the initial values of elements comma separated in braces. In such a case you may let a compilator automatically put the number of elements, instead of writing it yourself:.
Undoubtedly all this is ok, but… Unfortunately it is useless. We should somehow get to real data! For example, current prices, time, amount of free money and so on. Of course we cannot do without real data. To get access to them, we should simply refer to a corresponding built-in array. There are several such arrays, for example:. You see, the last bar index number is 0, next to last is 1 and so on.
There are also built-in common variables. For example Bars shows the number of bars in the current chart. It is a common variable, but it was declared before you and outside your script.
This variable exists always, like other built-in arrays and variables. Suppose you decided to calculate a mean value of maximal prices of all bars in the chart. For this purpose you alternatively add each element to a variable, for example so:.
I can tell you only this: it may work, but it is absurd. For such purposes there are cycles. Note, that all operations are absolutely similar, only the index changes from 0 to variable Bars-1 value. It would have been much more convenient somehow to determine a counter and using it refer to the array elements.
We can solve this task using cycles:. You see, the cycle starts with a key word for. There are other types of cycles, for example while , but we will not learn them now. Then in quotes point semicolon separated counter, cycle operation conditions, counter increase operation.
In a general case it can be presented like this:. Count declaration : int type is used for the counter. The name of the variable-counter does not matter. You should initialize the primary value, for example by 0. Counter operation conditions : it is all easy.
Here you determine a condition, and if it is true, the cycle goes on. Otherwise the cycle is ended. For example in out case:. It is clear, that the cycle will go on while the variable-counter is less than variable Bars. After that the cycle stops. Counter change : if we do not change the counter in our case increase it? The cycle will never end, because the condition will never be fulfilled. For better understanding of the cycle meaning, I have written a code that will perform a cycle with describing comments:.
The counter can be changed in a different way. For example, you do not have to increase it each time by 1. You can do like this:. Such applications significantly enhance traders' abilities when performing operations in the Forex market. The flexibility of the MQL4 language allows users to develop complex programs with large amount of calculations while accurately manage almost all trading robot and indicator parameters.
MQL4 contains the basic indicators necessary for analyzing current and historical quotes, and has built-in functions for managing trading orders. But if you are serious about your trading, then hiring the right forex coder can work wonders. Not only can this help your trading, but you can focus on new ways to trade the markets. I write this guide to help those who are new to the world of forex development and strategy coding. This guide should assist you in the right direction.
There is also a summary of the top three forex development marketplaces you can use in this endeavor. An MT4 developer is a coder who is proficient in using the mql4 programming language.
The MT4 developer can create custom scripts or indicators. You can then use these scripts on your Metatrader 4 trading platform. Traders may require from time to time, their own proprietary indicators or other trading tools.
This programming language is used mainly for MetaTrader 4 trading platforms only. It is not as common comparing to Python or other easy to learn programming language you come across these days.
Because of this, the cost for MT4 development is also slightly higher. Mql4 is the file extension given to scripts, indicators etc. You can open this file extension and easily edit its contents. Once the file extension. This is is the executable file. You can distribute this executable file if you want to share your trading strategies or custom indicators. The advantage is that with the executable.
Many commercial trading systems and even expert advisor files are in. This is done in order to protect the code from being misused or re-distributed or enhanced. You can get to the bottom of this reading the following lines. This type of data is useful for variables and functions which by their nature can only be integers. It may be the number of positions, the number of chart candles, the difference between the prices in pips, and the like.
The value of the variables of this type is limited to the number 2 in both the positive and negative spectrum. If we need a higher number, we need to use a derived data type, such as int or long. An example of the introduction of an integer variable and assignment of a specific value is shown in the following line. In the code, it can be written as true and false or as 1 and 0.
This means that the computer understands this type as an integer. We use the string data type for data in which we want to insert text or a string of any characters. The beginning and end of the string have to be always enclosed in quotation marks. We use a decimal number where the value is not inherently an integer but can also have decimal places up to If we determine a variable or function as the data type color, the value we input in it will be understood by the computer as a specific color code according to its internal color palette.
We have three options for informing it which color we want. The easiest option is to write it in words. However, the color name must be one of the web colors the MQL is able to distinguish. Another option is an integer number notation. On the Internet, it is usually used in the form of the so-called hexadecimal code.
The color hexadecimal code can be retrieved from any simple text or graphics editor. There are more options to enter the color code, however, they may be considered as less practical.
This data type is, of course, used to write dates and, if need be, time as well. The formats rrrr. Seconds, minutes and hours are facultative.
However, if the day, month or year are missing, the compiler will notify us of error. Even in this case, the date is converted to an integer number, for the purposes of the processing unit computations as the number of seconds that have passed since The date and time You will most likely never enter the number in this format, but it may happen that where you expect the date, a fantastical number like this one pops up due to some kind of error.
The cause will then be known to you. In practice, a date is seldom explicitly entered into variables. Typically, variables which bear time in them are in some way derived for example from the current time, for which we have the functions TimeCurrent and TimeLocal functions.
Now you already know why this is this way, which will make your work with data considerably easier. This data type is used to create groups of data of the same type. We may assign values to the data, but we do not have to, as they will be assigned automatically. Enumeration must be declared inside curly brackets.
In this basic series, we more than likely will not need enumerations. We will be able to read about them in articles beyond the scope of this series. It is precisely variables that will be discussed in the next episode. What is a variable and what does it do in the program? How do I create a variable? How do I assign it a value? Into what types of variables can they be divided? Work with variables is absolutely unavoidable in any program. A variable acts as the holder of a certain value we assign to it.
The value of the variable is stored in computer memory until changed again by another operation. Using variables, the program can store and present information in various forms. However, you will also be using auxiliary variables which will only operate within the code so their use will not be apparent to the user from outside. You might not feel much informed by these definitions but you will find them clear soon enough from practical examples. The introduction of variables into the program is called declaration.
It is very easy. To introduce a variable one has to only know the name and data type we wish to input. We explained data types in the previous episode. The introduction will be performed by writing the data type identifier and then the name of the variable. The name can only contain English characters. Special characters, including the dot, for example, may not be used. A declaration is an operation, it is necessary to write a semicolon at the end of it. We will learn why in the next episode dealing with operations.
There can even be more variables of the same type at the same time, their names only have to be separated by a comma:. This way, we have declared six variables to which we are planning to input decimal numbers. If any of the variables were of a different type, we need to declare them separately. The first value assigned to a variable is called initialization. Initialization, i. The options are numerous. Initialization can be performed by direct assignation:.
However, the variable Today must be declared as a string type. Once again, do not forget the semicolon at the end. Declaration and initialization can be combined into a single operation on a single line, like this:.
On the previous two lines, we have introduced an integer variable of the value 3 and the color Yell with the value Yellow and Lemon with the value Lime. Above, we have seen the creation and work with custom variables. In the MQL framework, however, there is also a number of predefined variables we do not need to declare or initialize. If we use them in the code, they turn pink and automatically contain the appropriate value. These variables contain specific data about the market, the chart on which the program is running, and other characteristics of the Terminal.
Below, you will find a table with these variables and the values they contain. You will probably never use some of them while others are used in almost every program. By clicking on the variable name, you will open its detailed description at mql. Maybe you paused at the array type variables and looked for them in this episode. However, they deserve their own chapter so we will go through them in the next episode.
Now, just briefly on the division of variables to global and local. Whether a variable is global or local depends on the part of the program in which it is declared.
If the variable is declared in the code header outside the body of all functions we talked about program structure in the fourth episode , it is a global variable. Such a variable is available to all of the functions of the program — both main and custom ones. In other words, it can be used with the same name and current value in all parts of the program.
However, this type of the global variable must not be confused with global variables which are available even for the entire terminal and all its other programs. Those are operated using a set of functions. This special type of variables will be discussed in a separate article.
Conversely, any local variable is a variable defined inside one of the functions. This is then available only for that function alone. If it is used in another function, it will not be detected, or the compiler will mark it as an error and force you to repair it.
This other function can also have a variable declared with the same name but its value will depend only on the operations within this function. If you need to convert the value of a variable from one function to another, it can be done using the parameters of the function call. However, we will only talk about those in the episode of functions. As mentioned above, the next episode will expand on the issue of variables by the arrays which are used with the very important predefined variables, such as Open, High, Low, Close, Time and Volume.
What is an array variable? How to index its value? How are its declaration and initialization different from the normal variables? How do you find a specific value from a set of values? Why such variables exist and how will they make my work easier?
As we said last time, we need to allocate a part of the series to a piece on array variables, especially on the predefined ones which fortunately are their simplest instances. This is because these variables are used to initiate the characteristic values of candlesticks in the graph which are necessary for the formation of most trading systems and indicators.
A normal variable can only bear a single value at a time. In contrast, an array variable carries the whole indexed set of values which can be up to four-dimensional. Thanks to the indexes, we can then initiate a specific value from the set we currently need. At a given time, it is only possible to have access to one of the values in the set.
0コメント