![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
You've certainly made a big step forward in the main subject - you've mastered and begun to use functions, and congratulations to you, of course!)
I'm consolidating the material I've learned so far, as well as I've started studying for and while loops. Trailing, though in distant future, but it's an obligatory part of my self-study plan.
Regards, Vladimir.
...
By and large, the script is written correctly. It doesn't take into account the null value of Period_learning, but otherwise it's good.
Ok, Peter, I'll think how to complicate the script and apply if-else condition statement inside the function.
Regards, Vladimir.
Good day and good mood everyone!
I continue studying the MQL5 programming language. Taking into account the tips from Peter Konov, I am pasting the finalized code of the script that is a continuation of one of the tasks from the participants of this thread. The script has been tested in all modes. No problems detected. To begin with I applied the minimum number of input parameters. The script code is written in English, the comments to the code are in Russian, to ease the learning process. As I promised earlier, I tried to describe the script in a manner comprehensible to a pupil of the 1-st form of programming school.
Best regards, Vladimir.
Good day and good mood everyone!
I continue studying the MQL5 programming language. Taking into account the tips from Peter Konov, I am pasting the finalized code of the script that is a continuation of one of the tasks from the participants of this thread. The script has been tested in all modes. No problems detected. To begin with I applied the minimum number of input parameters. The script code is written in English, the comments to the code are in Russian, to ease the learning process. As I promised earlier, I tried to describe the script in a manner comprehensible to a pupil of the 1-st form of programming school.
Regards, Vladimir.
Fix one error and it will be perfect.
Regarding the function, I assume this is how the code should have been written:
Sincerely, Vladimir.About the function, I assume this is how the code should have been written:
Sincerely, Vladimir.Just fix one error straight away and it will be perfect.
Global objects, are initialized by default by constructor. For primitive (in our case, all but string) types it is 0. But for memory (read variables) allocated on the stack, they are not initialized. That's why global variables may be not initialized, remember that in this case they will equal zero. But absence of initialization (at the same time, get used to avoiding compiler-generated warnings right away, unless you know exactly what you're doing) is a serious issue, because reading an uninitialized variable leads to undefined behavior. For example, this code behaves differently in release and debug builds and no one can guarantee that when you change the compiler version or optimization settings its behavior will not change too:
Peter, on the subject of global variables, I haven't yet found in the literature that global variables need to be predefined. Do you have a link to the source to improve your knowledge in this matter? The MQL5 Reference does not contain an explicit reference to initialization:
The booltype is designed to store the logical values true or false, whose numeric representation is 1 or 0 respectively .
Examples:
bool a =true;
bool b =false;
bool c =1;
The internal representation is a 1-byte integer number. It should be noted that in boolean expressions, it is acceptable to use other integer or real types or expressions of these types instead of bool, and the compiler will not generate an error. In this case, zero will be interpreted as false and all other values as true.
Global objects, are initialized with default constructor. For primitive (in our case, all except string) types, it is 0. But for memory (read variables) allocated on the stack, they are not initialized. That's why global variables may be not initialized, remember that in this case they will equal zero. But absence of initialization (at the same time, get used to avoiding compiler-generated warnings right away, unless you know exactly what you're doing) is a serious issue, because reading an uninitialized variable leads to undefined behavior. For example, this code behaves differently in release and debug builds and no one can guarantee that when you change the compiler version or optimization settings its behavior will not change too: