- Introduction to Creating a Dynamic Label in MQL5 (00:00 – 00:17)
- Introduction to the tutorial on creating a dynamic label in MQL5 that shows the current ask price.
- Opening MetaEditor and Creating a New Expert Advisor File (00:17 – 00:43)
- Instructions on opening MetaEditor and creating a new expert advisor file named “Simple Chart Label”.
- Setting Up the Code Structure and Getting the Ask Price (00:43 – 01:32)
- Deleting unnecessary code and explaining how to get the ask price using ‘SymbolInfoDouble’ and ‘NormalizeDouble’ functions.
- Creating and Configuring the Label Object (01:32 – 02:20)
- Using ‘ObjectCreate’ to create a label object and setting its properties such as window, date, time, and price value.
- Setting Font and Size for the Label (02:20 – 02:59)
- Changing the font and size of the label using ‘ObjectSetString’ and ‘ObjectSetInteger’.
- Adding Text to the Label and Setting Position (02:59 – 03:52)
- Adding text to display the ask price on the label and setting its position on the chart.
- Compiling the Code and Testing in MetaTrader (03:52 – 04:44)
- Compiling the code and instructions on testing the expert advisor in MetaTrader by dragging it onto a chart.
- Demonstration of the Dynamic Label in Action (04:44 – 05:24)
- Demonstrating the dynamic label on a MetaTrader chart and showing how it updates with the changing ask price.
- Conclusion and Further Learning Opportunities (05:24 – 05:29)
- Concluding remarks on the tutorial and suggestions for further learning through other videos or a premium course.
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.