MQL5 TUTORIAL BASICS – 42 SIMPLE Accumulation Distribution EA

video
play-sharp-fill

 

  1. Introduction to Accumulation Distribution Oscillator and Moving Average (00:00 – 00:16) Introduction to calculating the accumulation distribution oscillator and using it as a filter for a simple moving average.
  2. Starting in MetaEditor and Creating a New Expert Advisor File (00:16 – 00:47) Instructions on opening MetaEditor and creating a new expert advisor file named “Simple IADEA.”
  3. Setting Up the Code Structure and Defining Variables (00:47 – 01:29) Deleting unnecessary code, including the ‘trade.mqh’ file, and defining variables for the ask and bid price, and creating arrays for price data and the moving average.
  4. Defining the Moving Average (01:29 – 01:57) Explanation on how to define a simple moving average for twenty candles and sorting it from the current candle downwards.
  5. Calculating the Simple Moving Average Value (01:57 – 02:26) Using ‘copy buffer’ to copy values for the moving average and calculating the current simple moving average value.
  6. Calculating Accumulation Distribution Oscillator Values (02:26 – 03:12) Using the ‘IAD’ function to calculate the current and last values of the accumulation distribution oscillator.
  7. Defining Conditions for Buy and Sell Signals (03:12 – 04:19) Setting conditions for when the ask price is above the moving average and the IAD is rising, and when the bid price is below the moving average and the IAD is falling.
  8. Executing Trades Based on Signals (04:19 – 04:47) Using ‘trade.sell’ and ‘trade.buy’ to execute trades based on the calculated buy or sell signals.
  9. Outputting the Signal and Finalizing the Code (04:47 – 05:00) Using the ‘comment’ statement to output the current signal and finalizing the code.
  10. Compilation and Testing in MetaTrader (05:00 – 05:29) Instructions on compiling the code and testing the expert advisor in MetaTrader using the strategy tester.
  11. Demonstration of the Expert Advisor in Action (05:29 – 05:59) Demonstrating the expert advisor working in MetaTrader, creating buy or sell signals based on the accumulation distribution oscillator and moving average.

 

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.