MQL5 TUTORIAL BASICS – 42 SIMPLE Accumulation Distribution EA

video

In this video we want to find out how to calculate this accumulation distribution oscillator and how to use it as a filter for a simple moving average, so let’s find out how to do that with mql5.
To get started please click on the 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 IADEA, now let’s click on continue, continue and finish.
Now you can delete everything above the on tick function and the two comment lines here, we start with an include statement for the file trade dot mqh, afterwards, we create an instance of ctrade that will be called trade.
Inside of the on tick function we need to get the ask price and the bid price, that is done by using symbol info double, either for symbol underscore ask or underscore bid.
We also create an empty string variable called signal, afterwards we need to create two arrays, the first one is for the price data and the second one is for the moving average, so let’s use array set as series to sort the price array from the current candle downwards, afterwards we define the moving average that is done by using the ima function.
Now if you don’t know how this works you maybe want to watch the other videos in this basic course video series, in our case we use a simple moving average for twenty candles, let’s also sort this one from the current candle downwards and now we use copy buffer to copy the values for three candles according to the my moving average definition that we have created here and store it in the array.
And to calculate the current simple moving average value we just need to look into candle zero of the moving average array and that value will be assigned to a variable called my moving average value.
Let’s also calculate the two values we need to find out of the accumulation distribution oscillator is rising or falling, that is done by using the IAD function for the current symbol and the current period on our chart, we use volume tick as the third parameter, afterwards we use copy buffer to fill the price array with price data for eleven candles according to the IAD definition that we have created here.
To get the current IAD value we just have to look for the value of candle zero in our price array and we get the value for the last IAD by looking into candle ten of our price array, so now we can define a few conditions, the first one if the ask price is above the moving average, that is the case when the candles are above the simple moving average line here that would be an uptrend and in that case I would like to know if the current IAD value is bigger than the last one, that would be true when the accumulation distribution oscillator is rising and if both conditions are true we assign the word buy to our signal. Otherwise, if the bid price is below the moving average value, like here where the candles are below the simple moving average and if the current IAD value is below the last one, that is true if the value is falling, that’s when we want to assign the word sell to our signal.
And if our signal equals sell and positions total is below one or in other words we have no open positions we use trade dot sell to sell ten micro lot.
Otherwise, if the signal equals buy and we also have no open positions we use trade dot buy to buy ten micro lot.
Finally, we use the comment statement to output the text, the current signal is, followed by the calculated signal.
Now if this was too fast for you or if you don’t know what all the code here does maybe you want to watch the other videos in this basic series, otherwise please click on the compile button now or press F7, you shouldn’t get any errors here and if this is the case please click on a little button here or press F4 to go back to Metatrader.
And in Metatrader, we click on view, strategy tester or press control and r, please pick the new file simple IADEA dot ex5, mark the visible mode here and start a test.
Here we are! Our little expert advisor is working, it’s creating buy or sell signals and in this little video you have learned how to calculate the value for the accumulation distribution oscillator and how to use it as a filter for a simple moving average and you have coded it yourself with a few lines of mql5 code.