MQL4 TUTORIAL BASICS 127 – SIMPLE ELLIPSE OBJECT

video

In this video we are going to create such a Ellipse object like this one. It is drawn from the highest to the lowest of the last 30 candles. So let’s find out how to do that with MQL Four. To get started please click on a little icon here or Press F four on your keyboard. Now you should see the Meta-Editor window. And here you want to click on File, New file, Expert Advisor from Template, continue. I will call this file Simple Ellipse Object.

 

Click on continue, continue and finish. Now you can remove everything above the on tick function and the two comment lines here. We start with this command. It is called Ihigest and it will find the highest candle for the current symbol on the chart and the currently selected period on that chart. We use Mode High to get the high prices for 30 candles starting from the current candle. That is candle zero and we can do the same thing using Ilowest to find the lowest candle.

 

This is also for the current symbol on the chart and for the currently selected period. This time we use Mode underscore Low also for 30 candles starting from candle zero. And we store the value in the variable called lowest candle. And before we create a new object, we want to use Object delete to delete all objects that are called Ellipse. The very first time we will not have such an object, but every time afterwards we will delete the old one before we create a new one. And to actually draw the object we use object create. The first parameter here is for the chart.

 

We want to use the current chart with the candles that is index zero. The second parameter is the name of the object. We will call it Ellipse. Parameter three is the object type, we use OBG_Ellipse here.

 

The next parameter here is the main chart or the sub chart. The one with the candles is Chart zero, but if you use something like an Oscillator, this would be the sub window one for the Oscillator. We don’t have that, so we use chart zero. Now we have to define four points. The first point is the point in time when the lowest of the last 30 candles has been drawn. The second point is the actual lowest price of the lowest candle.

 

Point three is the time when the highest of the last 30 candles has been drawn. And point four is the highest price of the highest candle. Now let’s set a few object parameters. That can be done by using Object Set integer. If you mark that and Press F one, you will see that there are some options. The first parameter is for the Chart ID. Once again we use Chart ID zero.

 

The second one is the name of the object, that is called Ellipse. The next parameter is what we actually want to change. In our case, we want to change the property color. If you Mark that one and press F1,  you will see that we have different properties for different objects. So depending on the object that you want to draw, you might have or have not an option available.

 

In our case we want to change the color. That should be available for all object types. And we want to set it to blue. And now let’s change another property. This time it’s the property object property fill. That’s the background color, we want 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 means, you maybe want to watch one of the other videos or maybe even the premium course on our website might be interesting for you. That’s why you also can find a link to the shop where you can download source codes like this one in case you don’t want to type everything. But for now please click on the compile button or Press F7 on your keyboard.

 

You shouldn’t get any errors here and if that is the case you can click on a little button here or Press F four to go back to MetaTrader. And in MetaTrader you want to click on View, Strategy tester or press control and R. Please pick the new file simple ellipse object ex four. Mark the option for the visible mode here and start your test. Here we are, the expert advisor is running and our object is drawn. So basically it works as designed and in this little video you have learned how to create an Ellipse object. And you have coded it yourself with a few lines of MQL4 code.