Data randomly appears in empty variables and Alert() in structure affects calculations.

 

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.

Documentation on MQL5: Common Functions / Alert
Documentation on MQL5: Common Functions / Alert
  • www.mql5.com
Alert - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
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.”

Reason: