I prefer to declare variables, structures and classes that I use in OnTick() globally (one time), rather than locally within OnTick(). I feel that it is more efficient and less time consuming considering that OnTick() is called so frequently. Yet I see that it is common practice to declare locally. Why is this?
- My Bid price is not updating in my code
- Simple EA Optimization: Declaring 2 times the main culprit about these EA's speed?
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
TomP3185: I prefer to declare variables, structures and classes that I use in OnTick() globally (one time), rather than locally within OnTick(). I feel that it is more efficient and less time consuming considering that OnTick() is called so frequently. Yet I see that it is common practice to declare locally. Why is this?
Encapsulation and portability of functions.
The contents of globally scoped variables may be altered by other functions. That may be a requirement, but if not, then locally scoped variables offer encapsulation and easier portability of functionality.
EDIT: Do a "Google" search about it, in languages similar to C/C++, to understand the concept better.
That's a good explanation, thanks Fernando.
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