I choose to see the changes as a good thing and as a simplified transition from MQL4 to MQL5, or a mixture of the two. If you want to continue to code in ‘old school’ MQL4 then you’re free to do so, nobody is forcing anybody to change the way they work to any large degree.
We’re being given options and as far as I’m concerned, that’s a good thing.
There are lots of new additions and changes that will be seen by some as a headache and by others as an exciting playground to learn new ways of doing things. It’s all about perspective and how you decide to view things.
Are you a ‘glass half full’ type or a ‘glass half empty’ type?
Enumerations in MQL4
Here’s a nice example of one of the new features in MQL4 that I really like. It’s a relatively simple thing and has been available in other programming languages for ages.
Enumerations are a neat way of grouping similar items together in much the same way as we can do with arrays. We could have an array called ‘arrDays()’ that would hold a collection of days or we could have an enumeration called ‘enum_days’ that does the same thing.
The main difference is that enumerations are constants so once they’re set they can’t be changed later, unlike arrays.
Sounds complicated at first but it’s really pretty straightforward and as always, check the help file for more examples.
OK so what’s the ‘improved inputs’ that I referred to in the title of this article.
Here it is…
The other week I wrote a simple dashboard so that I could monitor all the currency pairs offered by my broker and alert me when certain conditions were met.
Pretty standard stuff so far and it was just something I put together quickly for my own use.
I had already changed from ‘normal’ external variables to the new ‘input’ variables but did a bit more reading and found something interesting.
The new build of MQL4 allows you to use enumerations in your input variables and lets you have drop-downs and ‘friendly names’.
For my dashboard I was using a fixed font size which was fine because it was only for my own personal use. I wanted to utilize the new enumeration feature so thought it might be cool to have a small, medium and large setting.
As I say, there’s no pressing need for it but I just thought it would be cool.
The original font size variable declaration looked like this…
Then to use the new enumeration feature I just added a definition and changed the input type.
input e_fontSize fontsize=medium;
Now I get a pretty cool drop down that allows me to change the font size without having to input any numbers.
I used this as a simple example and since it’s only for my own usage there’s no real need. It was just to experiment with using enumerations in MQL4 and get some ideas as to how I might use them in the future.
The other thing to notice is that the comment that comes after each item in the enumeration is displayed in the settings. This way you can have a more ‘friendly’ and readable values for the end user.
If you take a look in the MetaEditor help file you’ll see that the new build of MQL4 already comes with a ton of built-in enumerations. The ones that immediately caught my eye were the ones relating to moving average settings.
Previously I would have to use the integer values in the settings which always caused confusion for my clients. I would have to include a comment both in the code and above the actual settings to explain what each number meant.
Now it’s possible to just use the built-in enumerations and take advantage of the cool drop-down boxes.
Take a look in the help file at ENUM_MA_METHOD and ENUM_APPLIED_PRICE to get more ideas.
There’s bound to be a period of teething problems as with any new piece of software, but on the whole I think the new changes to MQL4 will be good for everybody.
You can choose to either embrace the changes and make them work for you or you can choose to be one of the whiners and complainers.
I know which one I’d prefer to be.