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?
- Variables - Global Variables
- Variables - Formal Parameters
- Declaration/definition statements
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