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
First, make sure that you initialized all the variables with some meaningful defaults. For example, you are using BuyTicket before it is initialized, so it can be any value on the first run.
Excerpt from the MQL4 reference file (MQL4 Reference / Language Basics / Variables / Initialization of Variables):
If a variable is not initialized explicitly, the value stored in this variable can be any. Implicit initialization is not used.
So, in the following part add defaults to the variables:
And yeah, MQL4 has bugs and quirks, but most of the errors could be avoided just by reading the basics in the reference manual.
Also, there is an article on common bugs in MQL4 programs. Check top of the forum, you'll find the link.
First, make sure that you initialized all the variables with some meaningful defaults. For example, you are using BuyTicket before it is initialized, so it can be any value on the first run.
Excerpt from the MQL4 reference file (MQL4 Reference / Language Basics / Variables / Initialization of Variables):
So, in the following part add defaults to the variables:
That is true, however, it depends on the usage. Sometimes you just want to declare it because you know where the value will be taken from, and sometimes you do need to initialize it with something since it may not works correctly if it is not initialize with specific default values.
That is true, however, it depends on the usage. Sometimes you just want to declare it because you know where the value will be taken from, and sometimes you do need to initialize it with something since it may not works correctly if it is not initialize with specific default values.
He does not need to initialize variables at the place of the definition, but he definitely should initialize variables to some value before using them.
If he uses them before initialization, value is unpredictable. So are his errors. Before any deeper code analysis he should take care of this problem.
Modern compilers raise errors if you try to use uninitialized variables. MQL4 unfortunately does not, so the coder must be sure that everything is properly initialized.
You could point out to him 1 thing that he uses the var without proper initializations.
Read the second sentence in the first line of https://www.mql5.com/en/forum/151167/page2#954612
You could read the answer before criticizing it.
BTW, how are you helping here? "Smart" remarks do not help very much.
I did read before I post mine. I mean, show him one thing that relates to the var and that var is not initialized properly.
Hehe. GumRai beats it. XD
If I understand you correctly, you are saying that the fact that he uses uninitialized variables is not something to worry about just because I did not point out exactly what could happen because BuyTicket and some other variables contain some unknown values when the program starts?
Well, so be it. Let him use uninitialized variables. What could go possibly wrong?