Saturday, January 31, 2009

Education MQL II Lesson number 2

The company "Fxtest"

Halhalyan Arthur

Technical support for traders

artur@fxtest.ru



Hello, dear readers. Today, we explain in detail the types of variables, to get acquainted with the operators of assignments and instruction if - then.



2.1 Variable numeric type



The variables, as you know, we need to store any information, with a possibility at any time to apply it or change it. Variables numeric type, according to the logic of keeping the number.

var: K (0), N (0) / / Local variables K and N, their default value is 0.

/ / This is a numeric variable type, because default they are listed among the

/ / end of the description of variables, like any other instruction MQL

/ / Finish <,>. If you notice before each line is a double slash

/ / as indicated by One-line comments

/ * This is normal, polnostrochny comment * /

(

K = 1; / / assignment, usually equal sign <=>

N = 10 * 2 / / in the right part can be written mathematical expressions with four / / basic mathematical operations +, -, *, /

K = N +5;

N = (bid + ask) / 2;

K = K +10; / * mathematical expression is not true, because right-hand side is not equal to the left.

Virtually any programming language, including MQL, such an operation assignment is absolutely normal. Following the expression variable K to increase by 10. To better understand this point, you can take that to the sign of equality is the new value of the variable (which we want to get), but after the old value. Ie K = K +10, the new value of K equal to the old, plus 10. * /

);

You can copy all the text in the Meta Editor, from the word var before closing braces, along with descriptions, they are all commented out unnecessarily.



2.2 Variable string type



var: string1 ( "text"), string2 ( "toge text"), string3 ( "");

/ / Variables string type, because default equal to the text box

/ / variable name may contain a figure, but the name of a variable can not begin with numbers

(

string3 = "slovo";

string3 = string1 + string2;

/ * To work with text strings have only one string operator, indicated <+> variable string3, will be "text toge text" * /

);



2.3 Relative Operators



Used to compare two values of the same type. The first value is compared with the second, resulting in a logical True (true) or False (false). Less - '<', more - '>' as well - '=' is not well -'<>', less than or equal to -'<='; greater than or equal to -'>='.



2.4 Instruction if-then



Perhaps there is no torguyuschego expert who does not have this instruction. Since market situation is changing all the time, you need all the time that it is something to compare or verify. To do this, and use this manual.

If (condition) then (to the truth of what is happening with the conditions)

else (effect occurs when the falsehood conditions)

else - an optional part of the instructions

Example:

If k> n then k = k +1; / / 1st

If k> b then k = k +1 else k = k-1; / / 2nd

Notice in the second example, after the first action (a = a +1) is not a semicolon, ie before else <;> do not have to make. If you need to perform several actions that can be used construction begin: end; or {:.};

Example:

If k> b then (k = k +1; b = b-1;)

If k> b then (a = a +1; b = b-1;) else (k = k-1; b = b +1;);



2.5 Variable logical type



These variables can have only 2 values True (true) or False (false). They are used as flags to allow something, or prohibiting. With the variable type logical work logical operators: and, or, not.

Var: k (True), n (false);

(

k = FreeMargin> = 1000;

If not k then exit;

);

There is forced out of the expert, if the free margin is less than or equal to 1000.

We can also write (if k <> True), or (if k = False) and it will have one meaning. Instead of what if, after writing a logical variable and check it on the equality of true, you can simply write the variable, but instead of checking for equality False, in front of a variable is a logical operator is not, as in our case.

If k> 0 and b> 0 then exit;

The operator and (I) groups the conditions after the operation then executed only if the truth of all conditions.

If k> 0 or b> 0 then exit;

The operator or (or) selects at least one of the true condition. Ie If any of the two variables is greater than 0 steps.

The operator not (not), applies to the logical variables. For the variables used by the relative number of type operator is not equal to (<>)

In the next issue we will begin a special study of MQL. We will consider the treatment to the array of quotations and learn to open positions.

No comments: