In this little video we are going to trade this Indicator, it’s an Oscillator, it’s name the Accumulation Distribution Indicator and it will create buy or sell signals based on the value of the Indicator here. If we speed up the process you can see that it’s actually making a profit.
Now we want to find out how we can create an Expert Advisor that is able to create buy or sell signals based on the Indicator window here.
To do that please click on the little button here or press F4 in your Metatrader, 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 file: “CheckEntry_IAD” because that is what I am going to call in my main module, now let’s click on “Continue”, “Continue” and “Finish” and now you can delete everything above the “OnTick” function here and lets also remove the two command lines.
Usually we use the “OnTick” function because this function is called whenever a new tick is generated; a tick is any price change here on the chart.
We need a string value and we will call the new function check entry (CheckEntry) because that is what I’m using in my main module to create a signal, this is the German version for the MQL4 Forex Trading Framework; the English version still isn’t finished by now but you could also use your own module or download the Forex Trading Framework from my website later, but for now we want to continue with the check entry (CheckEntry) function.
One of the first things we need is to create a string variable for the signal that will also be called: “Signal” and we don’t assign a value because we are going to calculate that later.
So let’s define the IAD value (IADValue); that can be done with the MQL4 function: “iAD”, it is included in MQL4 and if you mark it and hit F1 you will see that it calculates the Accumulation Distribution Indicator and returns its value.
It has three parameters; the first one is the symbol – that’s actually our chart –, the second one is the time frame, we use a 1 minute chart here but another time frame would be 5 minutes or 15 minutes and the last parameter is for the shift. We could use the shift to move the Indicator to the right or to the left and for this simple example we assume that whenever the “IADValue” is greater than zero that will be a sell signal so we assign the word: “sell” to our signal. In the other case now the “IADValue” would be smaller than zero we would create a buy signal and assign the word: “buy” to our signal.
In the last step we use the “return” function to return our signal to our main module; in my case it’s the framework.
Here we would call the check entry (CheckEntry) function and that would return the value for the signal.
Now when you are done you click on “Save” because the entry module just needs to be saved, the main module needs to be compiled by clicking on the little button here or pressing F7 and that worked without any errors and without any warnings so now I can click here or press F4 to go back to Metatrader.
In Metatrader we use a little trick; please click on “Insert/ Indicators/ Volumes/ Accumulation Distribution”, we will go with the default values here and click on “OK” and now the Indicator window appears below the candles.
Now let’s right click into template here, select “Template/ Save Template” and save it as: “tester.tpl” because that is the template that is going to be used in your next back test.
Let’s click on save and to open the “Strategy Tester” we click on “View/ Strategy Tester” or we press CTRL and R, now I select the Forex Trading Framework and you would select your own main module, please enable the visual mode here and start a test.
And here is our little Expert Advisor at work you can also speed it up and in this little video you have learned how to create an Expert Advisor that is able to trade the Accumulation Distribution Indicator and you have coded the entry yourself with a few lines of MQL4 code.
Download “MQL4 TUTORIAL - ADVANCED IAD EXPERT ADVISOR”AdvancedIAD.txt – Downloaded 816 times – 459 B