This should be used with caution, taking in mind that many classes may be designed to deliberately override system methods for purpose. For example, I used this technique for implementing on-the-fly optimization of EAs.
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
I'll start...
I've been chasing a bug for hours and felt I'd share my new-found wisdom...
In case you aren't familiar with scope resolution - you might have run across some code where the function name is prepended with two colons and wondered why...
This resolves function to the global namespace (where the built-in function is found) which is critical when working within a class; ESPECIALLY when you're inheriting from a parent class - because a lot of classes tend to redefine the built in MQL global functions.
eg.
Here is where an issue will develop if you aren't in the habit of using scope resolution. Let's say I make my own class that inherits from CPositionInfo
Now let's imagine for a moment that we forgot that our parent class has implemented its own version of an MQL function name, Symbol() for example, and somewhere in your class code you call to the API to get the chart symbol.
Since your class has redefined the Symbol function you are no longer calling the function from the global namespace and could therefore get the wrong result. This is the correct way to call the global Symbol function
Get in the habit of using the global scope resolution when calling global functions (especially for the Symbol and Period ) or learn the hard way, like I did.