MQL5 TUTORIAL BASICS – 39 SIMPLE CHART LABEL

video

In this video we want to create a dynamic label like this one, it shows the current ask price, this is actually an object, we can modify the properties, so let’s find out how to do that in mql5.
To do that please click on a little button here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple chart label, click on continue, continue and finish.
Now you can delete everything that is above the on tick function and let’s also delete the two comment lines here.
We start by getting the ask price, that is done by using symbol info double for the current symbol on the chart, we want to know the ask price so we use symbol underscore ask – all in capital letters – and with normalize double and underscore digits we make sure that the ask price is shown with the number of digits for this currency pair.
Actually, that doesn’t work always, most of the time it will show five digits behind the dot, that’s because this currency pair has five digits behind the dot, but from time to time you will see that it shows additional digits here.
To create such a label we use object create for the current symbol, the name of the object will be label one and we use obj underscore label to define what kind of object we like to be drawn, the last three parameters here are used to define the window, I use zero for the main window, I don’t have any date time and any price value.
Let’s pick a font, that is done by using objects set string for the object on the main chart, that is called label one, I would like to change the object property font and set it to the font type I like, and with object set integer on the main chart for the property for the object label one I would like to set the font size to twenty four, let’s also add some text here, that is done by using object set string, once again for the chart window for label one, this time it’s object property text, I think we can leave out this zero here and I would like to have the text, ask price followed by the calculated value for the ask price.
To set a distance we use object set integer object property x distance, let’s set five pixels for the distance to the left border and finally, I want to set the y distance, that’s the distance from the upper border to ten pixels.
Okay, that’s it.
If this was too fast for you or if you don’t know what all the code here means maybe you want to watch the other videos in this basic video series or maybe even the premium course that you can find on the website might be interesting for you.
If you are finished you can click on the compile button here or press F7, that should work without any errors. I have one inconsistency here, that’s actually the chart id, let’s recompile the code, here we have another warning, conversion from number to string, that’s okay for this simple example and when you’re done you can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader we pick an empty chart, make sure that the navigator window is visible, otherwise you could press ctrl end to show it, now we can pick the new expert advisor that is called simple chart label and drag it on the chart, and as soon as the price changes you should see your new label here.
Let’s go back, change the font, re-compile the code and now it looks different, and in this little video you have learned how to create an object-oriented label right on the chart and you have coded it yourself with the few lines of mql5 code.