In this video, we are going to create a list of predefined values that can be picked by the user to pick an entry. So let’s find out how to do that with MQL5. To get started please click on a little icon here or press F4 on your keyboard. Now, you should see the Metaeditor window until you want to click on file. New file, Expert Advisor from template, continue. I will call this file simple multiple input. Click on continue, continue and finish. Now you can delete everything above the ontick function and let’s also remove the two comment lines here, we start by creating a list. This is an enumeration, as you can see. The keyword here is Enum. And if you mark it and press F1, you will see that enumerations are a limited set of data that is predefined. For example, you could use it for 12 months and it is created like this. We have several items and we can also assign a value here.
The items are comma separated and now we are going to use this collection of data to create an instance. The trick is to use the input modifier because this will make our complete choice list available for the user input. The instance is called choice and we assign a default value here called random for random entries. I also would like to have a readable version, a string variable called entry. And inside of the ontick function, we can now check if the value for our choice is zero.
If that is the case, we have picked a random entry, so we assign the word random to our entry for the other entries. It is very similar and that’s how we check for the value. Let’s add a comment statement that will output the entry and the choice so that we see something on our chart.
Usually we would create some functions here, right now, we can pick entries, but nothing is happening as this video is just about how to make the enumeration available for the user input. So that’s basically it. If this was too fast for you or if you have no idea what all the code here does, you may be one to watch one of the other videos and the basic video series, or maybe even the Premium Course on our website might be interesting for you.
That’s also where you can find some offers for those source code files, in case you don’t want to type everything. For now, please click on View toolbar and click on the Compile button or press F7 on your keyboard.
You shouldn’t get any errors here. And if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader we want to pick an empty chart. Please navigate to the simple multiple input file and drag it on the chart and here comes the user input.
Now you can pick a choice. Let’s pick the EMA and click on, OK? And when the next tick comes in, we should see that we have chosen the EMA, the value for choice, this one, if you press F7, you can change the value. So now let’s pick the ADX and click on, OK? And now the entry is ADX. The value for choice is three. By the way, this once again was an idea of a Premium Course member, and if you are a Premium Course member and have an idea for a video like this one, just send me an email.
For now, you have learned how to create an Expert Advisor that is able to use an enumeration for user defined input variables that can be changed without the need to recompile the code, and you have coded it yourself with a few lines of MQL5 code.