MQL4 TUTORIAL BASICS – 48 SIMPLE CHART OBJECT

video

In this video we are going to draw an object on our chart for the opening period, you can’t see it right now but once the time on our computer reaches half-past ten in the morning you should see it on your chart.
I will try to speed things up a little bit here and here is the object, so let’s find out how to draw that with mql4.
To get started please click on the little icon 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 object, click on continue, continue and finish.
Now you can delete everything above the on tick function and let’s also delete the two comment lines here.
We will start with a string variable that is called end of opening period that will contain this string, it stands for half-past nine in the morning.
Let’s calculate the current time, that is done by using time local, we pass time underscore seconds as a parameter and the built-in function time to string will convert this date time type to a string variable called current time and afterwards, we can use a function that is called string find, it will open the string current time and it will look for the string end of opening period. Remember this is the string here and the result will be stored into this integer variable and it will be minus one whenever the string is not found.
I would like to draw an object that includes the highest of the last thirty candles so I use ihighest for the current symbol on the chart and the currently selected period on that chart.
This parameter mode underscore high must be written all in capital letters and we want to have the highest of the last thirty candles starting with candle zero.
Let’s repeat the whole process for the lowest candle.
That is pretty similar. This time we use ilowest for the current currency pair on the chart and the currently selected period on that chart. This time we use mode underscore low and this one is also for thirty candles starting with the current candle zero.
Let’s add an output on the chart. I will do that by using the comment statement and this one will output the text, current time followed by the current time that we have calculated here.
And once a day we should see that it is half-past nine and that is the case when end of opening period found is not equal to minus one.
And then we want to use object delete, the object with the name rectangle that will not exist the very first time but we destroy the old object from the day before.
And afterwards, we can create a new object with the same name. The object type is obj rectangle in this case. If you mark this expression and press F1 you will see that there are also a lot of other objects.
For example, you could use something like a label or a button. All those objects have different parameter settings. In our case this parameter stands for the current main chart, this is the time value for the current candle zero.
We want our object to be drawn from the highest candle to the lowest candle and in this parameter we define that we want to have it for thirty candles.
Let’s close this one, and we are almost done.
Well, if this was a too fast for you or if you don’t know what all the code here does, maybe you want to watch one of the other videos in this basic video series first or maybe you are even interested in the premium course. You can find that one on our website.
For now, please click on the compile button or press F7 on your keyboard. I don’t see 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 you can click on view, strategy tester or press control and r, please pick the new file simple chart object dot ex4, mark the visual mode here and start a test.
Here we are! It’s nine in the morning. We should see the rectangle in a few seconds, exactly now and here it is!
So in this little video, you have learned how to draw an object directly on the chart and you have coded it yourself with a few lines of mql4 code.