In this video we are going to create a simple object for a label.
This is a dynamic label that will show us the Ask Price and this label is an object and we are going to use the Object Create function and a few objects set functions to create the exact label you see here.
So let’s create an MQL 5 Expert Advisor that is going to create an object for us.
To do that, please click on the little button over here or press the F4 key on your keyboard.
And now you should see the MetaEditor and in the Meta Editor you want to click on File, New, Expert Advisor from Template, Continue, call it Simple Object Label, Continue, Continue.
Now we can remove everything above the Ontick function and we want to delete the two comment lines here.
And because we need something to show, we are going to get the Ask Price.
That can be done by using the function symbolinfodouble, for the current symbol and the current Ask Price and we use that digit here, because some symbols have only three digits after the dot, while other symbols have five digits.
And now we want to create an object by using ObjectCreate for the current symbol.
We will call it Label One and we will use the constant OBJ_Label, because that is the constant we need to use to create a label and we could choose a lot of options here.
And we don’t need a sub window, we don’t need a specific time, and we don’t need a specific anchor point for a price.
So that’s it and after we have created our label we want to use the function ObjectSetString for the current chart and the project we have called Label One.
And with OBJProp_Font, we can set the font to any kind of font we like.
In the next step we want to set the font size by using ObjectSetInteger on the current chart for the Label One object by using OBJProp_FontSize and the size of the font should be twenty four, and with ObjectSetString and OBJProp_Text, we will assign this text here and the value of the Ask variable we have calculated here.
And now we want to set the distance from the left border by using ObjectSetInteger for Label One and we will use OBJProp_Xdistance and a five and with OBJProp_Y distance ten we would set the distance from the upper border.
Okay that’s it, now please click on compile.
We have zero errors and three warnings here, because we used implicit conversion from String to Number, Number to String and String to Number but for this simple example it will be okay.
So please click on the little button over here or press your F4 key to go back to Meta Trader.
And in Meta Trader please click on View, Strategy Tester or press the Control and the R button.
And in the Strategy Tester you want to select the Simple Object Label.ex5 file, please make sure to enable the visualization mode here and click on start.
And now you should see the Ask Price in the upper left corner here.
And now I want to change the X distance here, that’s the distance from the left border and after I recompile the code and start a new test you see that our object has moved.
Now let’s change the font and the font size, recompile the code.
Start a new test and now we have a bigger font and a completely changed font type.
Okay, now you know how to create an object for a label, to use it in your MQL5 Expert Advisor for your Meta Trader5 and you have created it in less than five minutes with a few lines of MQL5 code.
Download “MQL5 - Simple Object Oriented Label from MQL5 Tutorial”SimpleObjectLabel.txt – Downloaded 303 times – 697 B