In this video, we want to check out this Oscillator here. It’s a very popular one. It is called the MACD Oscillator. We want to calculate the main signal for this one. So let’s find out how this is done with MQL5.
The Mac D oscillator is shown on a separate chart below the candle chart.
It has two values that show a value as a signal.
In this case we want to calculate the main line signal.
To use it, we build a separate MQ5 file and put it in the same directory as the other Platin System files.
CheckEntryMacD.mq5 is the name of the file, and it only has one function called CheckEntry.
The buy and sell signals for our system are calculated and returned by this function.
In fact, oscillators aren’t meant to make signals. Instead, they are used to confirm or filter out other signals.
But that doesn’t mean we can’t use them, since all we need for our trading system is a clear and well defined entry signal.
We start by putting the signal into a string variable.
That will be sent back to our main function later, but first we have to calculate it.
We also have to make an array for data about prices.
And with ArraySetAsSeries, we arrange our array and we want to sort it from the current candle 0 downwards.
MQL5 comes with an included function to calculate the MacD and that function is called I MacD.
We pass the symbol as the first parameter, followed by the period that is currently selected on our chart.
Three more values follow to define the period for the fast exponential moving average, then the slow exponential moving average and the signal period.
The values are 12, 26 and 9 as these are the standard values for the MacD oscillator.
The last parameter is used to define how the signal should be calculated.
We want to use PRICE_CLOSE here to use the close price.
With CopyBuffer we will now fill our array, according to the definition that we have created.
We do that for buffer 0 as that is the main buffer for the MacD oscillator.
We want to start with the current candle, that is candle 0.
And we want to store the value for 3 candles, the target is our price array.
Now that we have done that, we can calculate the current value by looking at the value of candle 0 in our price array.
If that value is bigger than 0, we want to sell and that is when we assign the word sell to our signal.
If the value is below 0, that would mean that we want to buy, therefore we now assign the word buy to the signal.
And at the end of our function we want to return the MacD signal to our main module, which is the one with the OnTick function.
Please don’t forget to save your entry file, but you actually don’t have to compile it right now.
The compilation is done in the main module, but before you do that, find the include statement for the entry signal and change it to use our new file, CheckEntry MacD.mq5.
By putting two slashes at the beginning of a line, you can comment out other entry modules.
After that, press F7 or click the compile button to compile your main module and the entry signal file that came with it.
There shouldn’t be any problems.
If you run into problems, you might want to buy the Premium course or watch one of the beginner videos to learn how it works.
OK, by now, you should have a working version for this entry signal for the MACD Oscillator. If you want to, you could also calculate the difference between the main line and the signal line here. But in this little video, you have learned how to calculate the main module for the MACD Oscillator. I will see you in the next video. Thank you for watching.