Direct answer
MACD (Moving Average Convergence Divergence) is calculated from moving averages of a selected price series. In the most common version, it uses two exponential moving averages (EMAs) of the same input price: a “fast” EMA and a “slow” EMA. The MACD line is the difference between those EMAs. A separate EMA of the MACD line becomes the signal line, and the histogram is the difference between the MACD line and the signal line.
A moving average in this context is calculated from historical data points using a rule that assigns weights to past observations. EMAs weight recent data more heavily than older data, which is why MACD reacts faster than a slower, purely “averaged over time” approach.
Mechanism or definition
1) Choose the input series (the “price” for the average)
Both MACD and a moving average require a time series of numbers sampled at regular intervals (for example, closing prices per bar). Typical choices for the input price include:
- Close price series
- Another price component (such as open, high, low, or an average of them)
Once you select the input series, the moving average calculation is deterministic.
2) Moving average basics: EMA formula
An EMA smooths a time series by updating recursively.
Let the input series be (P_t), where (t) indexes time steps. An EMA with length (N) is computed using:
- Smoothing factor: (\alpha = \frac{2}{N+1})
- Recursive update (for (t) after initialization): [ EMA_t = \alpha,P_t + (1-\alpha),EMA_{t-1} ]
Initialization matters. A common practical initialization is using the first available price (or a simple average over the first (N) points) to set (EMA_{N}) or the earliest EMA value in your computation window. Different software may initialize slightly differently, which can shift early values.
3) MACD lines and histogram (typical parameters)
The standard MACD structure has three plotted components:
- MACD line
- Signal line
- Histogram
Let:
- (N_{fast}) be the fast EMA length
- (N_{slow}) be the slow EMA length
- (N_{signal}) be the signal EMA length
Compute two EMAs of the same price series:
- (EMA^{fast}t) using (N{fast})
- (EMA^{slow}t) using (N{slow})
Then the MACD line is: [ MACD_t = EMA^{fast}_t - EMA^{slow}_t ]
Next, compute the signal line as an EMA of the MACD line: [ Signal_t = EMA(MACD)t\text{ using length }N{signal} ]
Finally, the histogram is the difference: [ Histogram_t = MACD_t - Signal_t ]
These formulas show the core “mechanics”: MACD is not a single moving average; it is a difference between two moving averages, followed by another moving average applied to that difference.
Evidence or example (calculation steps with explicit assumptions)
Assumptions for this example:
- You have a time series (P_t) sampled once per bar.
- You use the close price as (P_t).
- You choose (N_{fast}=12), (N_{slow}=26), and (N_{signal}=9) as typical lengths.
Step-by-step:
- Compute (\alpha_{fast} = 2/(12+1)) and (\alpha_{slow} = 2/(26+1)).
- Create (EMA^{fast}t) using: [ EMA^{fast}t = \alpha{fast} P_t + (1-\alpha{fast}) EMA^{fast}_{t-1} ]
- Create (EMA^{slow}t) using: [ EMA^{slow}t = \alpha{slow} P_t + (1-\alpha{slow}) EMA^{slow}_{t-1} ]
- Compute the MACD line at each time step where both EMAs exist: [ MACD_t = EMA^{fast}_t - EMA^{slow}_t ]
- Compute the signal EMA of the MACD series with (N_{signal}=9): [ Signal_t = \alpha_{signal} MACD_t + (1-\alpha_{signal}) Signal_{t-1} ] where (\alpha_{signal} = 2/(9+1)).
- Compute the histogram: [ Histogram_t = MACD_t - Signal_t ]
If you independently implement these steps using the same input series (P_t) and the same lengths, you should reproduce the same MACD structure. Small differences can still appear if you use a different EMA initialization or a different definition of the initial EMA value.
Limitations and risks
-
Parameter sensitivity MACD depends on (N_{fast}), (N_{slow}), and (N_{signal}). Changing these lengths changes the responsiveness and scale of the values, even though the underlying formula remains the same.
-
Data and alignment issues MACD computations require consistent time indexing:
- All series must use the same sampling frequency.
- The chosen input price series must match between your data source and your formula.
- If you compute EMAs on different bar definitions (for example, “close” vs. another price), results will differ.
-
Insufficient history and initialization Because EMAs need prior values, early MACD values can be unreliable if you start computing too close to the beginning of your dataset. EMA initialization choices (first value vs. average over (N) points) can affect early readings.
-
Interpretation failure mode MACD components are mathematical transformations; they do not automatically indicate a profitable or correct outcome. Treat them as descriptive features of the chosen time series rather than as a standalone decision rule.
-
Non-stationary behavior Market time series can change their statistical properties over time (for example, volatility regimes). Even if your calculation is correct, the same numeric pattern can behave differently across different regimes.
Verification and next question
To verify your own calculation, check these items:
- Confirm the EMA smoothing factor (\alpha = 2/(N+1)) is used consistently.
- Confirm you are using the same input price series (P_t).
- Ensure you apply (MACD_t = EMA^{fast}_t - EMA^{slow}_t) before computing the signal EMA.
- Ensure your histogram uses (Histogram_t = MACD_t - Signal_t).
- Compare a small window of computed values against a second independent implementation to catch initialization or alignment differences.
If you want, also review how the meaning of MACD changes when you alter the input price or the lengths (N_{fast}), (N_{slow}), and (N_{signal}). You can explore related explanations via internal pages such as macd and moving average and how settings change how do settings change macd and moving average.