Announcement:
  • If you need to open an account, you can contact customer service to guide the operation.
  • Customer service WeChat: Jin-DaoCheng
    1. Home > Foreign Exchange School

    Forex Intelligent Trading MQL4 Language Tutorial (3)

    4.2. The instruction structure of MetaQuotes 4 language

    4.2.1. Variable declarations and statements

    Preserving temporary data during calculations requires the use of variables. Variables are described in reserved words, variables, permutations, and definitions at the beginning of this program. He allows the use of negative forms of these words, namely "Variables, Arrays, and Defines". There is always a declaration description of the starting variable in the middle of these words. The differences between these words are as follows: "variable" statement simple variable, "array" statement permutation, "define" statement appends user-defined variables, similar to pre-defined user variables, which can be modified by setting the dialog box, that is, from outside. However, unlike pre-defined variables, user variables can be changed during calculations within the program.

    Variable declaration syntax:

    Variable: name (initial value); here the name is the name of the variable; "initial value" is the initial value of the variable. The initial value defines the type of the variable - number, string, or logical value.

    An example of a numeric variable declaration:

    Variable : Counter( 0 );

    An example of a string variable declaration:

    Variable: String1 ("arbitrary string");

    An example of a logical variable declaration:

    Variable : MyCondition( false );

    Array declaration syntax:

    Array: ArrayName [Array length] (initial value); where the array length has one or several (up to 4) digits - number [, number [, number [, number]]].

    In the MetaQuotes 4 language, an array may be 1-, 2-, 3-, 4- elements in length. In general, an array is a set of variables that can be found by the same name, and the array is located in successive rows, and the serial number (number) of the array elements is given. Arrays are convenient for sorting the same type of data. A typical example of an array is the historical data of the transaction end point, such as closing, opening, high, low, and trading volume. These data are used as a single-element array. For example, Close [5] refers to the closing value of 5 trading periods back. A two-element array might be a simple table in which the first component is a row and the second component is a column.

    Array: MyTable [10,5] (0 ); // a table with 10 rows and 5 columns.

    ...

    Print (MyTable [2,4 ] ); // Print the 4th element of the second line

    An array may contain any type of numeric value - numbers, strings, or logical values, but it should be of the same type, where the initial values are specific when the array is declared.

    Additional user-defined variable declaration syntax:

    Definition: Name (initial number); where the name is the variable name; initial number is the initial numeric value of the variable.

    It should be noted that additional user-defined variables may be of numeric type only. As mentioned above, user-defined variables can be modified during the calculation of the program. These modifications can only be applied to the current period of the Expert Advisor until the particular Expert Advisor is removed from the chart or the operation of the client's end point is completed. When a new Expert Advisor period is launched, the user-defined variable values are reinitialized.

    4.2.2 Exit statement

    The exit report interrupts the operation of the intelligence system software. It is also known as the termination of a predetermined program.

    Click to inquire about transaction account opening

    Please indicate the source: https://www.daoctech.com/fxschool/1977.html

    Disclaimer: The content of this article does not represent the views of the Institute of Foreign Exchange. The content is for reference only and does not constitute investment advice. Investors operate accordingly at their own risk.