In this video we are going to create such an object here. It’s a Gann Fan object, and we want to find out how to code that with MQL4. To do that, please click on a 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 one SimpleHighGannFan. Click on continue. Continue and finish.

Now you can remove everything above the OnTick function, and let’s also remove the two comment lines here. The first thing I want to do is to calculate the number for the candles on the chart. I can do that by using WindowFirstVisibleBar. If you mark that and press F1, you will see that it will return the index of the first visible bar in the current chart window. That’s the number of the bar not the value. And the result will be assigned to this variable.

The next step is to calculate the number for the highest candle, and that can be done by using iHighest. If you mark that and press F1, you will see that it will return the maximum value. In our case, for the current symbol on the chart and the currently selected period on that chart, we use MODE_HIGH because we want the high prices. You could also use numbers, but this one is better to read.

And I would like to calculate the highest price for all the candles on the chart, starting from the current candle, zero. Now that we know how many candles we have on our chart, and we know which one is the highest candle, we want to use ObjectDelete to delete former objects with that name, SimpleHighGannFan, because whenever we want to draw a new object, we want to remove the old values.

This object will not exist the very first time we call the function, but afterwards, we want to use it every time. That will remove the old object before we create a new one. And to create a new one, we use ObjectCreate. That can be used to create different objects.

Here is the list with the object types. There are several object types. Depending on the type you want to use you need to pass different parameters. In our case, we are using this one to create such a Fan object. So let’s go through the values. The first one is zero. That’s for the current chart. The second one is the name of the object. In our case, SimpleHighGannFan, parameter three is the object type. And we are using OBJ_GANNFAN. Please use capital letters.

The object should be drawn in the main chart. That’s windows zero. I would like to start with the highest candle and we are using the point in time when the highest candle was drawn. The next parameter is for the high of the highest candle. And I would like to draw until the point in time where we have the current candle zero. And the last point is the highest price for candle zero. You can modify these values, but for this simple example, it’s good enough. That’s the object create part.

Now let’s modify two properties. The first property I want to change is the color. And I can do that by using ObjectSetInteger for chart ID zero. And for the object that is called SimpleHighGannFan, the property I want to change is called object, property, color. And I would like to have orange.

Let’s set another property. And that one is called object, property, ray. And it will create a kind of prediction because it will draw the object to the current candle and into the future. So, let’s set this property to true and that’s about it.

If you have no idea what all the code here does, or if this was too fast for you, maybe you want to watch one of the other videos in our basic video series. Or maybe even the premium course on our website might be interesting for you. For now, please click on the compile button or press F7 on your keyboard. You shouldn’t get any errors. And if that is the case, you can click on a little icon here or press a four to go back to MetaTrader.

And in MetaTrader, we want to click on view, strategy tester or press control and R. Please pick the new file, SimpleHighGannFan.ex4. Mark the option for the visual mode here and start your test. Here is our little object. It works as designed. And in this little video, you have learned how to create a Fan object on the chart, and you have coded it yourself with a few lines of MQL4 code.