MQL4 TUTORIAL BASICS – 77 SIMPLE AWESOME INDICATOR

video

In this video, we are going to calculate this awesome oscillator here and we will also be able to define user signal values for the entries, so let’s find out how to do that with mql4.
To get started please click on a 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 awesome indicator, click on continue, continue and finish.
Now you can delete everything above the ontick function and let’s also remove the two comment lines here.
We start with an input variable, this input modifier will make it possible to let the user change the property in the expert advisor settings, it’s a floating type variable, we will call it signal value and this is the initial value and it can be changed by the user inside of the expert properties later on without recompilation.
Let’s continue by creating a string variable called signal, we will not assign a value here because that needs to be calculated.
And to get the current value for the awesome oscillator we use the included function iao, this one comes with mql4 and it has only three parameters. The first one is for the current symbol on the chart, the second parameter is for the period that we have selected on that chart, and the third parameter here is for the shift, we don’t use that so it is zero and that’s all to get the basic value here but to avoid confusion about rounding problems I would like to convert it to a better format so I will use a function called normalize double, the first parameter here is the value that we have calculated, the second parameter here is for the number of digits behind the dot so our awesome value here will be better to read in the comment statements.
Now let’s define the entry conditions if the current awesome value is bigger than the signal value that we have defined here we would consider that to be a sell signal, so we assign the word sell to our signal.
In the other case if the awesome value is below zero minus the defined signal value – that would be the negative value here – and if this expression is true we want to assign the word buy to our signal.
So whenever we have a buy signal and the return value for orders total is zero – that would mean that we have no open orders and we want to buy – and that’s when we use order send to buy ten micro lot.
In the other case if the signal equals sell and we have no open orders that’s when we want to sell and now we use order send to sell ten micro lot.
Finally, we use the comment statement to make some outputs on the chart I would like to see the awesome value on the chart please notice that I used double to string to prevent that we see exponential expressions here and the last two things on the chart will be the signal value for buy and for sell trades so that’s about it.
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 or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button here or press F7 on your keyboard, you shouldn’t get any errors and if that is the case you can click on a little button here or press F4 to go back to Metatrader.
And in Metatrader please open an empty chart and click on insert, indicators, Bill Williams, awesome oscillator, we will go with the default values here, so let’s click on okay, here is the oscillator and now please right-click into the window and select template, save template and save it as tester dot tpl, you can override the current value just tester tpl used in the strategy tester, otherwise, we wouldn’t see anything, so now that we have done that please click on view, strategy tester or press control and r, select the new file, simple awesome indicator dot ex4, mark the option for the visual mode here and start a test.
Here we are! The expert advisor is running but we don’t see any signals because the values that we have defined are too high, so let’s stop the current test, click on expert properties and let’s change that value and click on okay, now restart the test, here we see the newly defined value and as soon as this value for the indicator is reached we see a sell signal, so our little expert advisor is working as expected and in this little video you have learned how to create an expert advisor for the awesome oscillator that is able to trade us