Possible pre-conditions for start the discussion: 1. To determine the trend, it uses three exponentially smoothed moving averages: FastEMA, MediumEMA and SlowEMA. How to Buy Robots and Indicators. Still, he was intrigued by the fact that the majority of 1-percenters in the United States made their billions in the stock market. The EA will copy all positions without delays Additionally integrated notification in situations requiring user attention Buttons for re. Customize your indicator the way you want!




Creation of a Normal Program. Structure of a Normal Program The outstanding feature of a normal program is its structure that allows your to easily use some user-defined functions or other. For convenience, user-defined functions are usually formed as include files. As a rule, a normal program contains all three special functions that call the necessary user-defined functions for execution. User-defined functions, in their turn, can call other user-defined functions for execution.

An Expert Advisor can contain user-defined functions with the most diverse properties. Some functions, for example, are intended for tracking events and convenient data output, other functions are used to form trade requests, the third functions are metatrader 4 mqh for various calculations, for example, for defining of trading criteria, calculation of order costs, etc.

The decision on what functions to use in a program depends on the EA purpose and on what service the program is intended to provide the user with. Block diagram of a normal program Expert Advisor. The arrows in the diagram show the relationships between functions. For example, the order accounting function in the EA is called from the special functions init and start ; it can also be called from any other location in the program. In the right part of the diagram, the connecting arrows are shown that symbolize the possibility to call one user-defined function from another.

For example, the function defining trading criteria cannot be called from any special function, but it can be called for execution by a trade function. The data function is called from the special function deinit and, if necessary, from other functions, for example, from the error processing function, trade functions, or from the event tracking function. The include file of variable declaration cannot be called from any function, since the code contained in it is not the description of a function that can be called and executed.

This file contains the lines of global variable declaration, so it is just a part of an EA. In order to understand the way the different parts of an EA interrelate in, let's consider the order of creation and use of include files. If an application program contains a great variety of program lines, it is sometimes difficult to debug it - the programmer has to scroll the program text many times in order to make changes in the code in one or another location.

In such cases, for convenience, the program can be divided into several fragments, each formed as a separated include file. Include files can contain any code fragments to be used in the program. Each function used in the program is usually formed as an include file. If several functions metatrader 4 mqh logically interconnected, one include file may contain the description of several user-defined functions. Metatrader 4 mqh the section Information about an Accountwe consider an example of the protection code that prevents from unauthorized use of business programs.

In the Expert Advisor check. Checkthe description of which is directly contained in the source code of the EA. In the EA usualexpert. However, in this case, the function is metatrader 4 mqh as the include file Check. The function returns TRUE, if the conditions of using the application program are complied with. Otherwise, it returns FALSE. The include file Check. Check : It is easy to note that the name of the include file is the same as the name of the function it contains.

This is not required by the rules of MQL4. Generally, the name of an include file is not required to be the same as the name of the function it contains. It becomes even clearer, if we consider that one file may contain the description of several functions or of a program fragment that is not a function at all. However, the practice of giving an include file the same name as that of the contained function is feasible. In order to include the program fragment contained in the file, you should use the directive include.

The directive include can be specified in any location in the program. However, all included fragments are placed at the beginning of the source text file. Preprocessor will replace the line include. If the file name is enclosed in quotation marks, it will be searched in the current directory, namely, in the directory that contains the basic file of the source text the standard directory is not viewed.

Below is a normal Expert Advisor, usualexpert. All include files are placed in the head part of the program. In blockwe included into the program standard files stdlib. It is not always necessary to use these files in the program. For example, file stderror. If error processing is not provided in the program i. At the same time, it is usually necessary to include these files in a normal program. In blockthe program includes some files containing the description of user-defined functions.

Using the directive include in the line below: the source text of the program includes the user-defined function Check. Programmer can see the source code of the EA in this case, usualexpert. However, the source text of the program is modified at compilation, namely, each line containing the directive include. Thus, an executable file. An example of an include file containing a program fragment that is not the function description is file.

This file is included in the program text in the line: According to the rules of MQL4, any variable including global ones. For this reason, the file. For the same reason, all global variables are placed in this file. In some rare cases, it is technically possible to declare a global variable in an include file that describes the function, in which the value of this variable is first used in the program.

In such cases, it is necessary to keep the file including order. In other cases, it is even technically impossible to do this. For example, if we have two include files, each of them using two global variables, one of which is declared in one file and the other is declared in the other file, then we will get an error when compiling such a program, since, regardless the file including order, one of the variables is used before it is declared in the program. This is why it is a usual metatrader 4 mqh in a normal program to declare all global variables, without any exceptions, in one file that is included in the program before other files containing the description of user-defined functions.

In block of the include file Variables. In blocksother global variables are given, the sense of which will become clear upon considering the corresponding user-defined functions. The subsections of this section represent include files, each containing the description of the user-defined function of the same name. Structure of a Normal Program. Trading Criteria Defining Function. The outstanding feature of a normal program is its structure that allows your to easily use some user-defined functions or other.

The conditions of using the program are considered as complied with, if:. It is easy to note that the name of the include file is the same as the name of the function it contains. Using the directive include metatrader 4 mqh the line below:. This file is included in the program text in the line:. According to the rules of MQL4, any variable including global ones. Creation of a Normal Program Order Accounting.

MetaTrader 5 Trading Platform.




How to Use Metatrader 4


What's New in MQL4. source code MQH and MQ4 files implemented into other for each copy of MetaTrader 4 terminal on your computer via the terminal menu or. MQL4: automated forex trading, strategy tester and custom indicators with MetaTrader. WebTerminal; Documentation; Book; TA; Code Base; Articles; Freelance; Market. Open a $, demo account for 30 days on Metatrader 4 platform.