In my last article about improved input settings in mql4 I told you about enumerations and how they allow you to utilize drop down menus in your EA's settings. That was certainly a great improvement to the way settings are handled in MQL4 but there's another feature that you should be using.
If you're familiar with the original style of MQL4 coding you've probably used 'extern' variables to facilitate input from users. Since build 600 of MetaTrader 4 there's a new kid on the block.
Input variables or settings can now be declared as either 'extern' or 'input' and the difference between the two is pretty straight forward.
If you intend to change the values of the variable within your code you would declare them as 'extern' just as you did before. Changing the user settings within your code is not really a good idea and could potentially introduce bugs and errors that you didn't account for and are hard to track down.
That's why MetaTrader have introduced the 'input' storage class which is the preferred way to handle external settings. With these types of variables you can not change the values from within your code. This is a better way of handling user settings as it limits them to what they are actually intended for.
If you wanted to change their values from within you code you would have to assign them to other variables that you would then manipulate. This is 'good practice' as it clearly states your intentions within the code and reduces the chance of introducing bugs.
Using the 'extern' storage class won't break your code but if you don't intend to change the values within the code - which you shouldn't really - then consider changing them to the 'input' storage class.
Here's another neat benefit that's been introduced since build 600.
Naming of variables is a whole other topic and one that I'll discuss in another article but there was a glaring issue in the previous version of MT4. Whatever you decided to call your variables would be exactly what the end user would see in their EA settings.
Now depending on how you named your variables this could cause some confusion and the fact that you're not able to include spaces in variable names meant having to seperate them with a dash or underscore.
In the new version you can declare 'friendly names' for the variables in comments immediately after the variable. It's these 'friendly names' that will appear in the EA settings and makes it much simpler for the user.
Here's an example of what I mean...
//| MyFirstEA.mq4 | //| Copyright 2014, Automated Trading Software | //| http://automatedtradingsoftware.co.uk | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, Automated Trading Software" #property link "http://automatedtradingsoftware.co.uk" #property version "1.00" #property strict input double dLots = 0.1;// Size of Lots input int iTakeProfit = 200;// Take Profit input int iTrailingStop = 0;// Trailing Stop input int iStopLoss = 30;// Stop Loss input int iMagicNumber = 12444;// Magic Number
And here's what the end user sees when they look at their EA settings...
This works for all external inputs including 'extern', 'input' and 'enum'.
The new build of MetaTrader 4 is a great improvement on what was already a pretty great coding language. MQL4 is perfect for novice coders and the new additions to the language and programming environment are just the 'icing on the cake'.