MQL5 TUTORIAL – ADVANCED IAD-EXPERT ADVISOR

In this little video we are going to trade the Accumulation Distribution Indicator, it’s an oscillator that is shown below the candles.
We are using the Forex Trading Framework as a main module and if we speed up the trading process you can see how our Expert Advisors doing, an oscillator changes the direction from the upper to the lower end of the scale and now we want to know how we can create an Expert Advisor that is able to produce buy and sell entries.
To do that please click on the little button here or press F4 in your Metatrader and now you should see the Metaeditor window and here we want to click on “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “CheckEntry_IAD”, click on “Continue”, “Continue” and “Finish” and now you can remove everything above the “OnTick” function and the two command lines here.
Let’s change the “OnTick” function to string check entry (CheckEntry) because this is what we are going to call from our main module to calculate the signal.
In my case the main module is the Forex Trading Framework, basically it’s a collection of functions that can open and manage trades and you could also use your own main module, it needs to contain the “OnTick” function and you need to import the “CheckEntry_IAD” file we are creating here and the first thing we need to do is to create a string variable for a signal that will also be called: “Signal” and we don’t assign a value here because we are going to calculate that later on.
We need a price array, that’s a double array so it can hold floating type values and this array can hold several prices and with “ArraySetAsSeries” we sort the array downwards from the current candle and now we can actually define the properties for the IAD Expert Advisor.
We are going to use the “iAD” function, this function needs a few parameters; the first one is for the symbol name, the second one is for the period and the third one is for the volume type so let’s click on this reference and we lear that we can use the tick volume or the trade volume. We use “_Symbol” to automatically detect the type of the chart and “_Period” to detect the timeframe that is used on our chart. The third parameter is “volume_tick” to get the tick volume and now that we have defined the properties for the IAD Expert Advisor we use “CopyBuffer” to fill our price array for 3 candles starting with candle 1 and we fill it with data for the first buffer because it only has one line – that’s the blue line here – according to the IAD definition (IADDefinition) that we have created above.
To calculate the value for the current candle we simply look at candle 0 in our price array and assign the result to a new variable called: “IADValue” and if that value is below zero, so “IADValue” is smaller than zero here, we assign the word: “buy” to our signal.
In the other case if the “IADValue” is greater than zero we have a sell signal so now we assign the word: “sell” to our signal and in the last step we used the “return” function to return the signal to our main module; as I said, in my case it’s the Forex Trading Framework. If you don’t know what a framework is or how you can create one you could also download a version from our website.
So when I’m done I only have to save the new “CheckEntry_IAD.mq5” file by clicking on the little symbol here or pressing CTRL + S and now I need to recompile my framework by clicking on the little button here or pressing F7; that worked without any errors but I have a warning here… Oh, I made a mistake; this should be a double value! Well, let’s save the file again, recompile the framework and this time it worked without any errors and any warnings so now I can click on the little button here or press a F4 to go back to Metatrader.
In Metatrader I click on “View/ Strategy Tester” or press CTRL + R, let’s pick the main module here, enable the visualization mode and start a test.
And here is our little Expert Advisor at work and now you know how to code an entry signal for the IAD Oscillator and you have coded it yourself with a few lines of MQL5 code.

Download “MQL5 TUTORIAL - ADVANCED IAD EXPERT ADVISOR” AdvancedIAD.txt – Downloaded 37 times – 1,019 B