MQL5 TUTORIAL BASICS – 77 SIMPLE AWESOME INDICATOR

video

In this video, we are going to create an expert advisor that is able to trade the awesome indicator with the user-defined buy and sell value, so let’s find out how to do that with mql5.
To get started please click on this little symbol here or press the F4 key 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 the two comment lines here.
We start with an include statement to include the file trade dot mqh, this one comes with mql5 and it will give us the ability to use simplified trading functions. To do that we create an instance of the class ctrade, this is called trade.
In the next step, we are going to create an input modifier for a float variable, the variable will be called signal value and this is the value that we are going to use for buy and sell trades, we are able to modify that later in the expert advisor settings without recompilation.
Inside of the on tick function we need to calculate the ask price and the bid price, this is done by using symbol info double for the current symbol on the chart we either use symbol underscore ask or a symbol underscore bid and with normalize double and underscore digits we can automatically calculate the right number of digits behind the dot.
Now let’s create an empty string for the signal but we are not going to assign any value here because that needs to be calculated.
In the next step, we use mqlrates to get some price information because mqlrates stores the information about price, volumes and spread.
Let’s sort the price information array downwards by using array set as series and now we use copy rates to copy some data for the current symbol and the currently selected period, starting from candle zero for three candles and store it in the price information array.
We need a second array for the indicator values, let’s call that one price array and we use the included function iao that comes with mql5 to get the awesome oscillator definition for the current symbol on the chart and the currently selected period on that chart.
Now let’s use array set as series also for this price array and now we can use copy buffer to fill our price array according to the awesome oscillator definition that we have created here, we do it for buffer zero, we start with candle zero – that’s the current candle – and we store the price information for three candles in our price array.
Now let’s get the current awesome oscillator value that is done by looking into the value of candle zero inside of our price array and I use normalize double and I want to have six digits and that’s because this is also what we see on the original value here for the oscillator, so let’s find out if we have a buy signal that would be the case if the current awesome oscillator value is bigger than the signal value that we have defined here and if this is the case we consider that to be a buy signal so now we assign the word buy to our signal. In the other case if the awesome oscillator value is below zero minus signal value, so this expression is going to give us the negative value and if the current awesome oscillator value is below that we would consider that to be a sell signal and now we assign the word sell to our signal.
And if the signal equals sell and we have no open orders – that would be the case when the return value for positions total is below one – we use trade dot sell to sell ten micro lot. In the other case if the signal equals buy and we also have no open position we use trade dot buy and buy ten micro lot.
Finally, we use the comment statement to create an output on the chart. For the current signal we use double to string for the current awesome oscillator value, otherwise, we would see exponential values on the chart and below that we will also see the current signal value for the buy and the sell signal.
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 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, you shouldn’t get any errors here and if this is the case you can click on a little button here or press F4 to go back to Metatrader.
And in Metatrader, we click on view, strategy tester or press control and r, please pick the new file, simple awesome indicator dot ex5, mark the option for the visual mode here and start a test.
Here is our expert advisor! We already have the first buy trade here, let’s speed it up a little bit and we see that we have buy and sell signals here, now let’s stop the test, click on inputs and change the value here, let’s restart the test and now we have no signals because the current value is not high enough, so our little expert advisor works as expected and in this little video you have learned how to create custom buy and sell values for the awesome oscillator that can be changed without recompilation and you have coded it yourself with a few lines of mql5 code.