In this video we are going to trade the Accelerator Oscillator, it’s the fast running window here below the candles and the Accelerator Oscillator basically will tell us if something is overbought or oversold, so whenever the zero line is crossed here the signal changes. When the bars are drawn below the zero line we consider that to be oversold and we are going to use it as a buy signal, and when the bars are drawn above the zero line we consider it to be overbought and now we want to sell.
It’s profitable right now, so now we want to find out how we can automate the Accelerator Entry.
In this case I’m using the Forex Trading Framework as a main module because it is able to handle several trades at the same time and to create an entry module please click on the little button here or press F4. Now you should see the Metaeditor window and here you want to click on “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this one: “CheckEntry_IAC”, click on “Continue”, “Continue” and “Finish”, and now you can delete everything above the “OnTick” function and the two command lines here.
The first thing we need to do is to change the “OnTick” function, it will return a string and we will call it “CheckEntry”. Now we need to create an empty string for the signal; that will also be called “signal”, we don’t assign any value right now because we are going to calculate it later.
Let’s create an array for several prices that will be called: “PriceArray” (myPriceArray) and it’s a double array so it can hold floating type values and here comes the definition for the iAC Expert Advisor, we use the function “iAC” that is built in into MQL5. This function just needs two parameters; the first one is for the current symbol on the chart and the second one is for the period we have selected on that chart.
Now we use “ArraySetAsSeries” to sort the prize array (myPriceArray) from the current candle downwards and with “CopyBuffer” we fill our price array (myPriceArray) for 3 candles from the current candle 0 for buffer 0 according to the “iACDefinition” we have created here.
To get the value of the current candle we can select the candle 0 in our price array (myPriceArray) and the result will be assigned to a float variable called: “IACValue” and if the value is above the zero line – that would be the case when the bars are above the dotted line here – and the “IACValue” is greater than 0 we assign the word “sell” to our signal. In the other case if the value is below the zero line so the “IACValue” is less than 0 we would assign the word “buy” to our signal.
In the last step we need to return the signal to our main module by using the “return” function for the signal and in my case the main module is the Forex Trading Framework; that’s a collection of functions and you can basically trade any kind of entry signal with those functions, so I have included the new entry module here.
Let’s compile the framework. That worked without any errors and you could also use your own main module and if the compilation worked for you, you can click on the little button here or press F4 to go back to Metatrader.
In Metatrader we click on “View/ Strategy Tester” or press CTRL + R and in the Strategy Tester you have to select your main module, in my case it’s the Forex Trading Framework, if you haven’t created your own framework you could also download my version, it’s located on the website: forextradingframework.com.
Now we select any currency pair here, enable the visualization mode and start our test and now our Expert Advisor is running, it has already opened several trades and now you know how to create an Expert Advisor that is able to trade the Accelerator Oscillator and you have coded it yourself with a few lines of MQL5 code.