In this video we are going to create an object. This is a circle. It will show us the last, highest and lowest candle within the last 30 candles. So let’s find out how to do that with MQL Five. To get started 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 Ellipse Object as our circle is actually an Ellipse. Now let’s click on Continue, continue and finish. Now you can delete everything above be on Tick function and let’s remove the two comment lines here. We start by creating a variable for the highest and the lowest candle. Let’s also add two arrays for the High and the Low values.

We use Array set as Series to sort the High and the Low array from the current candle downwards. And now we can fill our array for the current symbol on the chart and the currently selected period on that chart. From candle zero to candle 30, we use Copy High to copy the highest prices of each candle in the High array. The same can be done for the Low array, we use Copy Low. Everything else is the same, but this time the values will be stored in our Low Array.

That makes it possible to calculate the highest candle by using Array Maximum. That will give us the highest value within our High Array. Starting from Index zero for 30 candles and as you might have guessed, for the lowest candle, we use Array Minimum and we look into our Low Array from candle zero to candle 30 and store the lowest value in this variable here. With MQL Rates, we create a Price Information array for the candle prices. This one as well needs to be sorted with Array set as Series and with copyrates for the current symbol on the chart and the currently selected period on that chart.

Starting from candle zero for all the bars on the chart, we want to store the values in our Price Information array. This expression will give you all the bars that are available. On a slow computer you might use a fixed value like here for 30 candles. Now we have everything we need, but before we draw the circle, we want to use Object Delete for the current symbol. And we want to delete all the former Ellipse objects. You might not have such an object, at least for the very first time when you start the Expert Advisor. But once the old object is deleted, we can draw a new one. That is done by using Object Create for the current symbol on the chart.

This is the object name. This is the object type. We use OBG_Ellipse. The object should be drawn in the main window. It will be started at the time when candle 30 has been drawn on the chart that is the left border. The upper border is for the highest price of the highest candle.

The right border is the point in time where we see candle zero, the current candle . And the lower border will be the lowest price of the lowest of the last 30 candles. Let’s set a few object parameters. I would like to change the object line color. That can be done by using object set integer. If you mark that and Press F1, you will see that we need to pass a few parameters. The first one is for the current chart ID. Zero means we want to do it for an object in the main chart with the candles.

The second parameter is the name of the object. The third one is the property that we want to change. In our case we want to change the object property color and we want to set it to blue. The next property I want to change is called object property fill. That’s the background color of the object and I want also to set it to blue and that’s about it.

If this was too fast for you or if you have no idea what all the code here does, you maybe want to watch one of the other videos in the basic video series. Or maybe even the premium course on our website might be interesting for you. That’s why you also can find source codes like this one in the shop. In case you don’t want to type everything. But for now please click on the compile button or Press F seven on your keyboard. You shouldn’t get any errors 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 click on view, strategy tester or press control and R. Please pick the new file simple ellipse object ex five. Mark the option for the visual mode here and start your test. Here we are, we see that our circle is drawn and it is moving. And in this little video you have learned how to create an expert advisor that is able to draw a circle object and you have coded it yourself with a few lines of MQL five code.