MQL4 TUTORIAL – SIMPLE ACCELERATOR EXPERT ADVISOR

video

In this video we are going to talk about the Accelerator Indicator, it’s an oscillator and it produces green and red bars. Whenever this zero line here is crossed by the bars we create a buy or a sell signal.
Now how can we create an Expert Advisor that is able to output buy or sell signals directly on our Forex chart?
To do that please click on a little button here or press F4 on your keyboard, and now you should see the Metaeditor window. Here you want to click on “File/ New/ Expert Advisor (template)” from template. Continue. I will call this one: Simple Accelerator (Simple Accelerator). Continue, continue and finish. Now you can remove everything above the “OnTick” function and the two comment lines here because now we want to create a variable for the signal – it will hold text, so we use a string variable call it signal – and so far, it has now value here because we are going to calculate that later on.
To calculate the “IACValue”, we use the built-in “iAC” function. If you select it and press the F1 key you will see that it takes 3 parameters. The first one is the symbol, the second one is the time frame, and the third one is the shift. If you click on insert “Indicators /Bill Williams /Accelerator Oscillator” you will see that we don’t have any shift value here, so we use _Symbol for the currently selected currency pair on the chart, _Period for the selected period on the chart – that can be 1 minute, 1 hour or 4 hours or anything else up to 1 month – and the last parameter here would be the shift, we use zero here because we don’t need to move the Accelerator Indicator to the left or to the right.
Now that the calculation is done we want to find out if the IAC value (IACValue) is above zero. We do that with an “if” statement; so, if “IACValue” is greater than zero (IACValue>0) that would create a buy signal, so we assign the word “buy” to the variable signal here. In the other case if the “IACValue” is below zero (IACValue<0) we want to create a sell signal by assigning the word “sell” to the variable called signal. Now let's create a screen output! We do it by using the comment function that will show the word “IACValue” followed by the calculated value and in a new line we want to output the word “Signal” followed by the calculated signal. That's it. Let's click the compile button or press F7 and now you should see no errors and no warnings and if that is true, please click on the little button here or press F4 to go back to Metatrader. In Metatrader you want to use a little trick, click on “Insert /Indicators /Bill Williams /Accelerator Oscillator”, click OK to get the default values, and now that the indicator window is shown you want to right click in the main chart, select template, save template, and use the name: “tester.tpl” because that is the file that is used for the back test. Now click on save and select “View /Strategy Tester” or press CTRL + R and in the Strategy Tester you want to select the “SimpleAccelerator.ex4” file. Let's enlarge this a little bit, mark the visual mode here and start your test! Here is your little Expert Advisor at work, actually it doesn't change, so I must have messed something up here. Let's go back to the source code! Oh, I missed the line to test out if the “IACValue” is really below zero, so let's fix that, recompile the code, stop the current test and start another one. Now it works! You can see buy or sell signals directly on your Forex chart and you have automated the output for the Simple Accelerator Index with a few lines of MQL4 code.