In this video, we are going to create an expert advisor for this indicator here. 


It’s the fractals indicator and the expert advisor is going to open, buy and sell trades based on this value. 


So let’s find out how to calculate that with MQL4.


To do that, 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 fractals EA click on, continue, continue, and finish. 


Now you can remove everything above the on tick function and the two comment lines here, we start by creating a string variable for the signal, but we don’t assign any values here. 


Now let’s actually calculate the values for the fractal indicator, and that is done by using I fractals.   


We need to pass a few parameters. The first one is for the current symbol on the chart. 


The second one is for the currently selected period on that chart. 


The third one is MODE_UPPER. If you mark that and press F1, you will see that MODE_UPPER represents a value of one. 


It is used for the upper line of some indicators, and one of them is ifractals. 


And we are going to calculate the value for candle two, because Ifractals is not creating the arrows for the current candle. 


It creates them for candles in the past. 


So if you would use candle zero here, you would get no values. 


Let’s repeat that, this time we are going to calculate the lower fractals value. 


This is pretty much similar, but this time we are using MODE_LOWER. And this also is the value for candle two.  


That’s the third candle because the current candle is candle zero. Now we can check the signal conditions. 


And if the lower fractals value is not zero, we want to check if the lower fractals value is below the lower price of candle one. 


And if that is the case, we consider that to be a buy signal. 


And now we assign the word buy to our signal. 


In the other case, when it is going down, we want to check if the upper fractals value is not zero. 


And the second condition is that we want to know if the upper fractals value is greater than the high price for candle one, that would be a sell signal. 


And that’s when we assign the word sell to our signal. 


Now we can check if our signal equals buy. And we also want to know if the return value for orders total equals zero.  


That would mean we have a buy signal and no open positions. 


And that’s when we use order send to open a buy position for 10 micro lot. 


In the other case, if our signal equals sell and we also have no open positions, we use order send to sell 10 micro lot and to see what’s going on, we add a comment statement that will  show us the upper value, the lower value and the current signal on our chart. 


And that’s about it. 


Well, 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 of the basic video series, or maybe even the premium course on our website might be interesting for you. That’s actually where you also can find a link for courses that contain all the source codes here. 


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 button here or press F4 to go back to meta trader.


And in meta trader, please pick an empty chart, click on insert indicators, Bill Williams, fractals, click on okay, here is the indicator. 


And now we can right click into the chart, select template, save template, and we save it as Tester.tpl, because this is the template that we are going to see in the strategy tester. 


You can override the current one, and now you can click on view, strategy tester or press control and R, please pick the new file Simple fractals EA.ex4, mark the option for the visual mode here and start your test.


Here we are, the expert advisor is running. 


I’m going to speed it up a little bit. And here is our first buy trade. 


You can see that we have values for the indicator. 


So our little expert advisor is working as expected. 


And in this little video, you have learned how to create an expert advisor for the fractals indicator, and you have coded it yourself with a few lines of MQL4 code.