Mikhail Sobolev: . If I restart the MT5 - for the first time it stores zero, as it should, for the next ones - some random value.
Not “as it should.” The documentation is clear; uninitialized variables contain random values. Initialize your variables; that is “how to fix it.”

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
Hi.
So I'm writing the script. I declare a variable (type double) and do not use it in the code before checking - and it has some random data. If I restart the MT5 - for the first time it stores zero as it should, for the next ones - some random value.
Or, the code with a structure does not work. I put Alert() inside the structure to check variables at some point - and behavior of the script changes. Data appears in the uninitiated variable. I pass new argument into Alert() - and variables value changes again. (Or the opposite: I'm looking at the variable that should store zero - and it stores zero and index is not trespassing array bounds.)
I've tried to google and search, didn't help. I've found some solution with data in variables (to initiate them explicitly), but for some reason it's not working again and even if it's working - maybe it's not the best solution? Probably it's only fighting a symptom.
I can tell more, but it is difficult and probably you already know what's going on and how to fix it. If not - I'll try to elaborate.
Thank you in advance.