MQL4 TUTORIAL BASICS – 49 SIMPLE WILLIAMS PERCENT RANGE EA

video

In this video we are going to create a simple expert advisor for the Williams Percent Range oscillator that you see right here on the chart, it will create buy and sell signals so let’s find out how to do that with mql4.
To get started please click on the little icon 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 Williams Percent Range ea, click on continue, continue and finish.
Now you can delete everything above the on tick function and the two comment lines here, we start by creating a string variable for the signal but so far we will not assign any values here because we are going to calculate that now. And to do that we use the included iwpr function that comes with mql4, it needs a few parameters, the first one is for the current symbol on the chart, the second one for the currently selected period, the third one here is for the number of candles because when you click on insert, indicators, oscillators, Williams Percent Range, you will see that it is calculated based on fourteen candles.
Now let’s click on ok, right-click into the chart, select template, save template and save it as tester dot tpl because this is the one that you are going to see in the strategy tester, so please click on save, you can replace the current one.
The last parameter here is for a shift value, we don’t need that so it’s zero and now we want to check if the current wpr value is below minus eighty, let’s actually call that value and that would be true when the signal is below the lower dotted line here and if that is the case we want to buy so we assign the word buy to our signal.
In the other case if the wpr value is bigger than minus twenty – that would mean that the signal is above this upper dotted line here – and in that case, we want to assign sell to our signal.
And if our signal equals buy and orders total delivers a value of zero – that would mean we have no open orders – and a buy signal and if that is the case we use order send to buy ten micro lot.
Otherwise, if our signal equals sell and we have no open orders we would use order send to sell ten micro lot.
Finally, we want to create a chart output that is done with the comment statement, we will see the text the current signal is and the calculated signal.
Okay, that’s it so far.
If this was too fast for you or if you have no idea what all the code here does maybe you want to watch one of the other videos in this basic video series first or maybe even the premium course on our website might be interesting for you. For now, please click on the compile button or press F7 on your keyboard, I don’t have any errors here and if this is also the case for you you can click on a little button here or press F4 to go back to Metatrader.
And in Metatrader please remember to save the template for the strategy tester and now we click on view, strategy tester or press control and r, please pick the new file simple williams percent range ea dot ex4, mark the option for the visual mode here and start a test.
And here is our little expert advisor at work, we see the first buy trade here so the program is working like expected and in this little video you have learned how to code an expert advisor for the Williams Percent Range oscillator and you have coded it yourself with a few lines of mql4 code.