MQL4 TUTORIAL BASICS – 95 SIMPLE LOW GANN FAN

video

 

In this video, we are going to create this kind of object. This is a LowGannFan object from the lowest candle to the current candle. So let’s find out how to do that with MQL4. To get started please click on a little icon here or press F4 on your keyboard.

 

Now you should see the Metaeditor window and you want to click on file. New file Expert Advisor from Template, continue. I will call this file simple LowGannFan, click on Continue, continue and finish. Now you can delete everything above the Ontick function and the two comment lines here. First, we want to calculate the number for the first visible bar. And that can be done by using this function. It is called Window First Visible Bar, that will return the index of the first visible bar.

 

So that’s not the value. That’s just the number.

 

Now we can calculate the number for the lowest candle on the chart. And that can be done by using the function ilowest, because that will give us the lowest value over a specific number of bars, depending on time, for the current symbol on the chart and the currently selected period on that chart. We use ModeUnerscoreLow because we are interested in the lowest prices of the candles, and that is for all the candles on the chart up to the current candle zero, before we create a new object, we use object delete, that will delete all the objects called simple LowGannFan.

 

Because we want to avoid that we draw several objects at the same time, the very first time we call this function, we will not have such an object. But afterwards, we want to make sure that we remove the old object before we draw a new one. Once that is done, we use object create to create a new object. And this will need a few parameters. So let’s go through the parameter values one by one. The first parameter is for the chart ID, that’s chart ID zero in our case.

 

The second is the object name. In our case it is called simple LowGannFan. You can call it whatever you like as long as you use the same name everywhere. Parameter three is for the object type. We are using OBJ_GannFan. If you mark that and press F1, you will see that there are other object types, depending on the type of the object, you would need to use other parameters. We are going to create this kind of object, and in the next parameter we are going to tell Metatrader that we want to draw it in the main window, that’s window zero, the one with the candles, the object should be drawn from the point in time where the lowest candle appears on the chart.

 

This is always the time scale and here are the values. The next parameter is for the lowest price of the lowest candle. So these two values here define the starting point. The object should be drawn to the point in time where the current candle is drawn and the last parameter is for the low of the current candle. And that’s it for this object creation. Of course, you could change the parameters here, but for this simple example, this is good enough.

 

Now let’s continue and change a few values, that can be done by using ObjectSetInteger for the current chart ID zero. We want to change a property for the object that is called simple LowGannFan. The property I want to change is called object property underscore color and I would like to see a red color. Let’s change another property. The first part is the same. But I would like to change object property, Ray, and set it to true, that will give us a kind of object prediction because that will draw the object to the current candleand into the future.

 

So far, so good. If this was too fast for you or if you have no idea what all the code here does, maybe you 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. 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 you want to click on View Strategy Test to or press Control and R, please pick the new object. Simple LowGannFan dot EX4 mark the option for the visual mode here and start your test. Here we are. The object is drawn and we see that it is also adjusted. Let’s zoom into the chart. We see that the Expert Advisor is working as expected. And in this little video you have learned how to draw a LowGannFan object right on your chart and you have coded it yourself with a few lines of MQL4 code.