# Understanding MACD from the ground up

Jun 4, 2023

“MACD , Golden Cross Up Dead Cross Down”

The majority of people’s understanding of MACD stops there!

In fact, I didn’t really understand what MACD was until I studied it in depth.

The official name for MACD is Moving Average Convergence / Divergence.
It means the variance of a moving average.

In other words, MACD is essentially a statement about moving averages!

Let’s take a look at the implementation of the MACD algorithm.

The MACD algorithm is calculated in five steps

1) Calculation of a fast period average fast_ma with a period of 12

2) Calculation of the slow period average, calculated as slow_ma, the period being typically 20

3) Calculation of the difference between the two SMAs, calculated as diff, where diff = fast_ma – slow_ma

4) Calculate the average period index of the diff, computed as dea, where diff = fast_ma – slow_ma

5) Calculate the difference between diff and dea, i.e., MACD = diff – dea

diff is Differential, which in mathematics means Difference.

dea is Differential Exponential Average, meaning that the average operation of diff is performed using the EMA method.

At this point, it is easy to understand that MACD is essentially a representation of the variance between the fast and slow averages

This is also evident in MT5, where the MACD chart we usually see is a double bar chart, whereas the MACD indicator in MT5 has only one line, DIFF, which is represented by a bar chart and the algorithm DIFF = MACD, which is a bit confusing for the first time DIFF is represented by bars and lines.

There is no difference that DIFF is represented by bars and lines, and there is no significant difference that MACD is the golden fork of DIFF or DIFF and DEA.

If you haven’t touched the MT5 part, you can skip it and go straight to the implementation algorithm of the MACD class code.

fast_ma = EMA(fast_period,close).

slow_ma = EMA(slow_period,close).

diff = fast_ma – slow_ma.

dea = EMA(diff,dea_period).

macd = diff – dea

When calculating averages, there is no right or wrong way to use exponential average EMA and arithmetic average SMA, but it depends on personal habits.

The key here is the choice between fast and slow periods, i.e., fast_period, slow_period

This is very important because it means which two SMAs the MACD is moving against.

The defaults of 12 and 26 are illogical to represent the variance between the 20 and 60 period SMAs.

Unless you know what you are doing, 12 and 26 are not wrong.

Otherwise, it is strange that the attached MACD points to 12,26 while the main chart points to 20,60.

As long as you don’t know what you are doing, it doesn’t mean it won’t work.

For example, let’s use a relatively short period to increase sensitivity, macd(15,50,5) to correspond to the variance of the 20,60 line.

The variance also reflects the strength of the trend

The essence of the MACD is the trend

5 1 vote
Rating
Subscribe
Notify of
0 Comment
Inline Feedbacks