This time we are going to trade an advanced version of the Mac D entry. I will speed the test up a little bit and now you can see that we are trading several positions here and that’s because we are using a framework. This framework basically is a collection of functions that are able to manage open trades and you can use any entry you like. Now how can we create in Mac D entry that can be used for framework? To do that please click on the little button here in Meta Trader and that should open the Meta Editor and in the Meta Editor you want to click on File, New, Expert Advisor from Template, Continue. I will call this one Check Entry_Mac D. Now click on Continue, Continue and Finish. And in this case you can delete everything because we are going to create a new function with the name Check Entry. It is a string function because it will return a string so let’s create an empty string without any value and it will have the name signal. We also need a price array so I would create one of the type double and that will be called My Price Array and now we want to define the properties of the Mac D Expert Advisor and that can be done by using iMac D for the current symbol on the chart and the current period, and these values 12, 26 and 9 can also be seen if you click on insert indicators, Oscillators Mac D. This is a value of 12 for the first EMA, the slow EMA has a value of 26 and the Mac D SMA has a value of 9. The calculation is based on the close price and that’s exactly what we do here so let’s sort our array from the current candle downwards by using array set a series for the price array we have created here and after that we can fill the array by using copy buffer for the Mac D definition and that we have created in this line we use zero for the first line. The current candle also is candle zero, we want to calculate it for three candles that’s the three here and afterwards we want to store the result in our price array.
So let’s get the value of the current candle, that would be candle zero in my price array and we store the value in a float variable called Mac D value and if the Mac D value is above zero we want to create a signal for a sell trade because we believe that the Mac D value is overbought and in the other case if the Mac D value is below zero, we create a buy signal. That’s about it, in the last step we want to return the calculated value to the main module by using return signal. Now let’s save the module and now I need to recompile the framework, if you don’t know what a framework is you can think of it as a group of functions that can be imported to manage your open trades. The only thing you have to do is to pick one of the entry signals and in the OnTick function it will check for a signal by calling the check entry function that we have created here and afterwards it calls the trade management and with the check for tick function and the trading framework we will handle the signal and open the trade, that’s a little bit more complicated but in this little video we are just talking about the entry.
Okay the compilation of the framework was successful, if you don’t know how to create a framework you might want to take the course on my website to learn it and I will also offer another way to get it in a few weeks so if you’re interested you can find everything about it on my website. Now let’s click on the little button here or press F4 to go back to Meta Trader and in Meta Trader I click on View Strategy Tester or I press control and R. And in the Strategy Tester I choose the Forex trading framework. Let’s pick a whole year, enable the visualisation mode and start the test. And here is how it looks like, I will speed it up a little bit for you and now you can see the results. It’s running pretty fast but I can still speed it up, I only have to disable the visualisation here. Let’s maximize this panel, start the test and here is how it works.
And that’s a way to do hundreds or thousands of trades in a few seconds and now our framework has finished and this is the end result. You can click on the results tab here and you’ll see that we would have made $3,360 and now you know how to create a Mac D entry for an automated trading framework and you have coded it yourself with a few lines of MQL 5 code.
Download “MQL5 Tutorial - Advanced MacD Expert Advisor”AdvancedMacD.txt – Downloaded 518 times – 851.00 B