MACD: Moving Average Convergence Divergence

The MACD, short for Moving Average Convergence Divergence, is an indicator that measures the gap between two exponential moving averages of price, a fast one and a slow one. It has neither ceiling nor floor: it is not a bounded oscillator, so it has no fixed overbought zone. Gerald Appel developed it in the late 1970s. This lesson gives the exact calculation of its three plots, the MACD line, the signal line and the histogram, worked by hand on ten candles, what each platform shows with the 12, 26 and 9 settings, how to read crossovers and divergences, and then what the indicator cannot tell you.

MACD: definition, what it measures and what it does not

The MACD asks the chart one question: is the average of recent prices pulling away from the average of older prices, and in which direction? TradingView's help page on the MACD defines it as a momentum indicator that measures the difference between two moving averages and gives an unbounded view of how they converge and diverge over time. When the fast average is above the slow one, the MACD is positive; when it is below, the MACD is negative; when the two meet, it comes back to zero.

StockCharts' ChartSchool places it across two families, trend and momentum: it starts from two moving averages, which are trend-following tools, and turns them into an oscillator by subtracting the longer one from the shorter one. It says straight away what the MACD does not do: because it is unbounded, it is not particularly useful for identifying overbought and oversold levels. It has no fixed scale like that of the stochastic oscillator, which runs from 0 to 100.

Its name is written 'Moving Average Convergence/Divergence' by StockCharts and in MetaTrader 5's help page on the MACD, and without the slash by TradingView. Convergence: the two averages move towards each other. Divergence: they move apart. StockCharts writes that Gerald Appel developed it in the late seventies; TradingView, that he created it in the 1970s and that Thomas Aspray added the histogram in 1986. Publishers do not file it the same way: a momentum indicator for TradingView, a trend-following indicator for MetaTrader 5, which nevertheless lists it in its oscillators menu. Pages consulted in October 2026.

Eighty-four candles and their 12, 26, 9 MACD
Eighty-four candles and their 12, 26, 9 MACD Invented price series, real calculation: exponential moving averages of the closes, settings 12, 26 and 9. Top: eighty-four candles, a fall, a fast rise, a pullback, a slower rise that closes higher, then a fall. Bottom: the MACD line as the thick line, the signal line as the thin purple line, the histogram as bars, green above zero and red below, and the zero line as the solid line. The MACD line starts at candle 26, the signal line and the histogram at candle 34. Price hits its low at candle 37; the MACD line moves above its signal line at candle 40 (first dot), still far below zero, at −1.94, and only crosses the zero line at candle 46 (second dot), when more than half of the rise is done. The histogram peaks at candle 50, four candles before the MACD line. In the shaded area, the dashes join two peaks: the highest close goes from 103.57 to 105.14, the peak of the MACD line drops from 2.57 to 1.85. That is a bearish divergence. On this series, drawn to show it, the fall follows; on a real chart, nothing guarantees it.

Calculating the MACD: MACD line, signal line, histogram

Step 1: two exponential moving averages of the closes. An exponential moving average, or EMA, gives more weight to recent prices. StockCharts' page on moving averages calculates it in three steps. The first value is the simple average of the first N closes. The multiplier is 2 ÷ (N + 1). After that, on each candle: EMA = (close − previous EMA) × multiplier + previous EMA. With the usual settings, the fast average covers 12 periods (multiplier 2 ÷ 13, or 15.4 %) and the slow one 26 periods (2 ÷ 27, or 7.4 %). MetaTrader 5's help page on moving averages writes the same recurrence in another form: EMA = close × P + previous EMA × (1 − P).

Step 2: the MACD line. MACD line = 12-period EMA − 26-period EMA. StockCharts, TradingView and MetaTrader 5 write the same subtraction, the fast average minus the slow one. The result is a price difference: it is counted in the unit of the chart, in dollars on a stock quoted in dollars, in points on an index.

Step 3: the signal line. It is a moving average of the MACD line itself: signal line = 9-period EMA of the MACD line in StockCharts' formula (multiplier 2 ÷ 10, or 20 %). Like any average, it trails the MACD line, and that lag is what makes the turns of the MACD line easy to spot.

Step 4: the histogram. Histogram = MACD line − signal line. It is positive when the MACD line is above its signal line, negative when it is below, and it passes through zero when they cross. StockCharts' page on the MACD-Histogram spells out what that stacking means: the histogram is an indicator of an indicator, four steps removed from price. The two averages, their gap, the average of that gap, then the difference between the two.

How much history it needs. With this calculation, the slow average only exists from the twenty-sixth candle, so the MACD line does too, and the signal line waits for nine MACD values: it starts at the thirty-fourth. The first values are not yet the right ones. StockCharts warns that an EMA depends on all the EMAs before it, and therefore on how much history is loaded, and says it calculates back at least 250 periods on its own charts.

The MACD worked by hand on ten candles

The prices are invented, and the settings are 3, 7 and 3 instead of 12, 26 and 9 so that the calculation fits in ten candles. The method is unchanged. The multipliers become 2 ÷ 4 = 0.5 for the fast average and for the signal line, and 2 ÷ 8 = 0.25 for the slow average.

Here are the ten closes. Candle 1: 100.00. Candle 2: 102.40. Candle 3: 103.60. Candle 4: 104.80. Candle 5: 105.00. Candle 6: 107.80. Candle 7: 110.00. Candle 8: 112.80. Candle 9: 115.60. Candle 10: 113.00. Price rises up to candle 9, then pulls back on the tenth.

The fast average, 3 periods. Its first value lands on candle 3: (100.00 + 102.40 + 103.60) ÷ 3 = 102.00. After that, half of the gap between the close and the previous average is added each time. Candle 4: (104.80 − 102.00) × 0.5 + 102.00 = 103.40. Candle 5: 104.20. Candle 6: 106.00. Candle 7: 108.00. Candle 8: 110.40. Candle 9: 113.00. Candle 10: (113.00 − 113.00) × 0.5 + 113.00 = 113.00.

The slow average, 7 periods. Its first value lands on candle 7: the sum of the first seven closes, 733.60, divided by 7, which is 104.80. After that, a quarter of the gap is added. Candle 8: (112.80 − 104.80) × 0.25 + 104.80 = 106.80. Candle 9: (115.60 − 106.80) × 0.25 + 106.80 = 109.00. Candle 10: (113.00 − 109.00) × 0.25 + 109.00 = 110.00.

The MACD line is their difference, from candle 7 onwards. Candle 7: 108.00 − 104.80 = 3.20. Candle 8: 110.40 − 106.80 = 3.60. Candle 9: 113.00 − 109.00 = 4.00. Candle 10: 113.00 − 110.00 = 3.00. It is positive because the fast average is above the slow one, and it grows for as long as the fast one keeps pulling away.

The signal line and the histogram. The signal line waits for three MACD values. Its first one lands on candle 9: (3.20 + 3.60 + 4.00) ÷ 3 = 3.60, and the histogram reads 4.00 − 3.60 = +0.40. On candle 10, the signal line reads (3.00 − 3.60) × 0.5 + 3.60 = 3.30, and the histogram 3.00 − 3.30 = −0.30. A single pullback of 2.60 was enough: the MACD line has moved below its signal line, although it still reads 3.00 and the fast average is still above the slow one. A bearish signal line crossover says the gap between the two averages is narrowing, not that the trend has reversed.

MACD settings, platform by platform

The usual settings come down to three numbers: 12 for the fast average, 26 for the slow one, 9 for the signal line, calculated on closes. StockCharts presents them as the typical settings and notes that other values can be substituted depending on trading style. Platforms keep those three numbers, but they do not all plot the same thing.

TradingView: the settings window reproduced on its help page shows the source, the close, then 'Fast length' at 12, 'Slow length' at 26 and 'Signal length' at 9. It adds two lists: the type of the two base averages and the type of the signal line, exponential (EMA) or simple (SMA), both set to EMA in that window. The indicator plots the MACD line and the signal line as lines, the histogram as colour-coded columns, and a zero line. StockCharts: (12,26,9) by default, histogram included; setting the last number to 1 removes the signal line and the histogram. thinkorswim: its documentation on the MACD lists a fast length, a slow length, a length for the average of the MACD, and an average type to pick from simple, exponential, weighted, Wilder's and Hull. It plots the value, its average, their difference and the zero line, and gives no default values.

MetaTrader 5 plots something else. The MACD indicator code published by MetaQuotes, the developer of the platform, keeps 12, 26 and 9 on closes, but it has only two plots: the MACD line, drawn as bars, and the signal line, drawn as a line. The bars in MetaTrader 5 are therefore not the histogram of TradingView or StockCharts: they show the MACD line itself. The difference between the MACD line and its signal line does exist, but in another indicator, 'Moving Average of Oscillator' (OsMA), which its code published by MetaQuotes describes as the MACD histogram.

Second difference: the signal line. MetaTrader 5's help writes it SIGNAL = SMA(MACD, 9), a simple moving average of the last nine values, and the code confirms it, where StockCharts' formula and TradingView's window use an exponential average. Same 12, 26 and 9, two signal lines. Recalculated on the candles of the diagram above from the same MACD line, the simple-average signal line reads 2.29 at candle 59 when the exponential one reads 1.96, and two of the four crossovers shift by one candle: the first bearish crossover lands on candle 58 instead of 59, the second on candle 74 instead of 73. The gap is thin, but it is enough for a crossover noted on one platform not to fall on the same day on another.

Reading the MACD: signal line, zero line, histogram

The signal line crossover. The MACD line moving above its signal line is read as bullish, the reverse as bearish. For StockCharts, these are the most common MACD readings, and a crossover can last a few days or a few weeks. MetaTrader 5's help makes it the basic rule of the indicator. StockCharts is more cautious: these crossovers call for due diligence before relying on them, those that occur at a positive or negative extreme should be viewed with caution, and volatility in the security increases their number. Its example counts eight crossovers in six months on one stock, four each way, some good and some bad.

The zero line crossover. The MACD line crosses above zero when the fast average moves above the slow one, and below zero when it moves back under. It is therefore a moving average crossover, read on a single line. Above zero, TradingView reads average upward momentum or a potential uptrend, and the reverse below. StockCharts adds that the MACD stays positive as long as an uptrend lasts, and shows both cases: one stock where these crossovers went with real trends, and another where seven of them followed one another in five months without any trend taking hold.

The histogram. It measures the distance between the MACD line and its signal line. It grows when they move apart and contracts when they come together: for StockCharts, that contraction is the first step towards a signal line crossover, and anticipating that crossover is what the histogram was designed for. In the diagram, it peaks at candle 50 and then shrinks for nine candles, while the MACD line keeps rising until candle 54 and only crosses its signal line at candle 59. The same page tempers this: short and shallow divergences in the histogram are much more frequent than long and large ones, and the crossover itself is what confirms.

The lag. All these readings come after price. StockCharts says so: the MACD is built from moving averages, moving averages lag price, and a signal line crossover can come late. In the diagram, price hits its low at candle 37, the MACD line only crosses its signal line at candle 40, and it only crosses zero at candle 46, when 58 % of the rise to the first peak is already done.

None of these readings is an order to buy or sell. They are conventions, to be tested on your market, your timeframe and your settings, with the method in the article on how to backtest a trading strategy. Tradoshi does not record the MACD at the time of your trades: the indicator is read on your chart. The journal is for the next step: you tag every trade taken on one precise reading, for example 'bullish crossover below the zero line', and the dashboard filters by tag to show what that reading produced for you.

Bullish divergence and bearish divergence on the MACD

A divergence appears when price and the MACD stop moving the same way. StockCharts gives both definitions. Bullish divergence: price records a lower low, and the MACD forms a higher low. Price confirms the downtrend, but the MACD shows less downside momentum. Bearish divergence: price records a higher high, and the MACD line forms a lower high. The rise goes on, with less momentum behind it. TradingView puts it in other words: falling peaks in the MACD as price rises might indicate the exhaustion of an uptrend, and rising dips in the MACD while price drops, that of a downtrend.

Two points made by StockCharts matter. A divergence is looked for on closing prices, since the MACD's moving averages are based on closes, and its example rests on clear troughs, in price and in the indicator alike. In the diagram, the shaded area shows one: the highest close goes from 103.57 to 105.14, and the peak of the MACD line drops from 2.57 to 1.85.

The warning comes from the same page: divergences should be taken with caution, because bearish divergences are commonplace in a strong uptrend, and bullish divergences in a strong downtrend. A trend often starts with a surge that pushes the MACD very high; it then continues at a slower pace, the MACD comes down from its high, and price keeps rising. StockCharts' example lines up four bearish divergences in four months on an index fund that kept moving higher. As long as the MACD line stays above zero, it writes, upside momentum is still outpacing downside momentum: in the diagram, it never drops below 1.50 between the two peaks.

The word does not mean the same thing everywhere. MetaTrader 5's help calls a bullish divergence the case where the MACD is making new highs while prices fail to reach new highs, and a bearish divergence the case where the MACD is making new lows while prices do not follow: it starts from the indicator, where StockCharts starts from price. TradingView, for its part, separates the regular divergence, which suggests the trend is weakening, from the hidden divergence, which suggests it will continue. Before comparing two readings, check which definition is being used. The histogram, finally, has its own divergences, measured against the MACD line and not against price: StockCharts sees them as a way to anticipate a signal line crossover.

The limits of the MACD

It lags. It is a difference between averages, and its signal line is an average of that difference. It confirms a move already under way, it does not announce it: in the diagram, more than half of the rise is done when it crosses zero.

With no trend, crossovers multiply. In a market that swings back and forth, the MACD line crosses its signal line and the zero line again and again with nothing following: those are the seven crossovers in five months of StockCharts' example. Knowing whether a trend is in place is another question, the one covered in the lesson on the DMI and the ADX.

It has no bounds. There is no fixed overbought or oversold level. StockCharts writes that a security's past extremes can be identified, but that nothing binds the MACD from over-extending beyond them during a sharp move. MetaTrader 5's help nevertheless presents it as useful for spotting overbought and oversold conditions, when the shorter average pulls away dramatically from the longer one. Two publishers, two views.

Its values cannot be compared from one instrument to another. The MACD line is a price difference, so it depends on the price level. StockCharts' example: it may range from −1.5 to 1.5 on a 20-dollar stock, and from −10 to +10 on a 100-dollar stock. A MACD of 2 means nothing without the security and the timeframe. To compare several securities, StockCharts points to another indicator, the Percentage Price Oscillator (PPO), which expresses the gap as a percentage.

The barest calculation in the family needs no average: momentum compares the close with the close n candles earlier, and the ROC expresses that gap as a percentage, which makes it comparable from one instrument to another. The lesson on momentum and the Rate of Change gives the three formulas that circulate under those two names.

It depends on the platform and on the history. Bars or lines, simple or exponential signal line, histogram included or filed under another indicator: the same name covers different plots, and an exponential average calculated on too short a history has not yet reached its value. Nor does the MACD say anything about the range of the candles: that is the question the ATR answers. It remains a tool from the moving average family, and the page on technical analysis explains why two tools from the same family do not make two confirmations.

Frequently asked questions

What is the MACD in trading?

The MACD, short for Moving Average Convergence Divergence, is a technical indicator that measures the gap between two exponential moving averages of the closes, 12 and 26 periods with the usual settings. It comes with a signal line, the 9-period average of that gap, and a histogram, the difference between the two. Gerald Appel developed it in the 1970s.

What is the best setting for the MACD?

The usual settings are 12, 26 and 9: they are the defaults on StockCharts, in MetaTrader 5's code and in the settings window shown on TradingView's help page. StockCharts mentions (5,35,5) as a more sensitive variant, and names no setting as better than another. Check the average type of the signal line above all: simple on MetaTrader 5, exponential in StockCharts' formula.

What does a MACD above zero mean?

That the fast moving average is above the slow one: recent prices are, on average, higher than older prices. StockCharts and TradingView read it as upward momentum. It is not an overbought level: the MACD has no bounds, and it stays positive as long as an uptrend lasts.

Why is the MACD in MetaTrader 5 different from the one on TradingView?

Because it does not plot the same thing. In MetaTrader 5, the bars are the MACD line itself, and the signal line is a 9-period simple average. On TradingView, the MACD line and the signal line are two lines, and the columns are their difference, the histogram. In MetaTrader 5, that difference is another indicator, the OsMA.

What is a bullish divergence?

According to StockCharts, a bullish divergence forms when price records a lower low while the MACD forms a higher low: the fall goes on, with less momentum behind it. It does not announce a reversal. The same page notes that bullish divergences occur often in a strong downtrend.

Key takeaways

  • The MACD measures the gap between two exponential moving averages of the closes. It is unbounded: it has no fixed overbought or oversold zone.
  • MACD line = 12-period EMA − 26-period EMA. Signal line = 9-period average of the MACD line. Histogram = MACD line − signal line.
  • 12, 26 and 9 are the usual settings. In MetaTrader 5, the bars are the MACD line and the signal line is a simple average; the histogram of other platforms is a separate indicator there, the OsMA.
  • Signal line crossover, zero line crossover, divergence: three reading conventions, all lagging price, and often wrong when the market has no trend.
  • A MACD value depends on the price of the security: it cannot be compared from one instrument to another. A bearish divergence is commonplace in a strong rise and does not, on its own, announce a reversal.

Going further

These blog articles dig into this lesson's ideas, one subject per article.

Join the Oshi Academy

The lessons teach you the theory, the community makes you practise. We swap trades, screenshots and silly questions there, and nobody sells signals.

Join the Oshi Academy