Читать книгу Expert advisor for MT4 for one evening - Evgeny Zhdan - Страница 5

The if-else conditional operators

Оглавление

The if-else conditional operators can be used left and right. If – means “if” clause, else – “if not, then”.

For example:

if (x <y) // If the content of the x keg is less than the content of the y keg

{

Do something here, for example, open an order. Or close another order, do anything you like!


} else // And if x is not less than y, do the task put in braces below

{

Do something here.

}

the use of the else operator is not must-have, it all depends on the specific task.

Two slashes – // – mean comments in the advisor code, right after the symbol. When you compile your Expert Advisor (turn your code into machine code, understandable for your computer), the comments will be ignored. If possible, you should write the comments for yourself, so as not to forget what has been done and why.

The blocks of comments are done like this:

/* this

is the commentary

block */

Anything put between the /* and */ symbols is also ignored by the compiler.

Cycles

There are for and while cycles in mql4. The for is used more often, but while is also popular.

for (int i=0; i <100; i++)

{

count something 100 times.

}

int i = 0 – assign a variable to work within this cycle; i <100 – the cycle runs 100 times, from 0 to 99; i ++ (increment) means that with each run (iteration) of the cycle, the variable i will be incremented by 1.

bool x = false; // assign value false for a variable x of bool type

while (x==false) // while x is false. Two equal symbols – == – mean comparison

{

/*

some conditions will come true here.

As soon as x is true, the cycle will stop.

*/

//for example

x = true;// set x to true after the first run

//and thus the cycle stops

}

In the process of writing an adviser, we will use both of these cycles, and you will puzzle them out easily.

Expert advisor for MT4 for one evening

Подняться наверх