This guide calculates MACD step by step on a model Nifty series, explains how to read the lines, the zero line and the histogram, compares settings, and covers divergence, the problem of measuring MACD in points, intraday use and the indicator's limits.
Key takeaways
- MACD line = 12-period EMA − 26-period EMA. Signal line = 9-period EMA of the MACD line. Histogram = MACD line − signal line.
- The MACD line is above zero when the 12-period EMA is above the 26-period EMA, and it crosses the signal line when its own momentum changes direction.
- The histogram turns before the lines cross. On the model series it reached its lowest reading on the day of the price low and turned up the next session, seven sessions before the bullish cross.
- MACD is measured in points, so its size depends on the price level. Values cannot be compared across instruments; the percentage price oscillator divides by the slower average to fix that.
- Faster settings give earlier and more frequent signals; slower settings give fewer and later ones. No setting removes the lag.
- Read MACD on the index or futures chart and trade options on that view. An option's own price chart mixes in time decay.
The model Nifty series
Every number on this page comes from one model series of 72 daily closes, a seeded random walk that is not market data. It is the same series used in the guides to RSI and moving averages.
| Phase | Sessions | Close at the start | Close at the end |
|---|---|---|---|
| Dip and slow rise | Days 1 to 25 | 24,800.00 | 24,920.15 |
| Rally to the high | Days 26 to 32 | 24,959.45 | 25,500.00 |
| Fall to the low | Days 33 to 44 | 25,473.00 | 24,158.55 |
| Recovery | Days 45 to 72 | 24,181.20 | 25,867.60 |
The high is 25,500.00 on day 32 and the low 24,158.55 on day 44, a fall of 1,341.45 points or 5.26%.
How MACD is calculated
Each exponential moving average follows the usual rule: EMA today = close × k + EMA yesterday × (1 − k), with k = 2 ÷ (N + 1). The multipliers are 0.1538 for the 12-period EMA, 0.0741 for the 26-period EMA and 0.2 for the 9-period signal line. An EMA puts the most weight on the latest closes, so the 12-period EMA reacts faster than the 26-period one, and the gap between them widens when the price moves quickly.
The parts appear in stages, because each needs its own history:
| Value | First available | Starting value on the model series |
|---|---|---|
| 12-period EMA | Day 12, the average of the first 12 closes | 24,657.23 |
| 26-period EMA | Day 26, the average of the first 26 closes | 24,746.13 |
| MACD line | Day 26 | 24,841.89 − 24,746.13 = 95.76 |
| Signal line | Day 34, the average of the first 9 MACD values | 159.23 |
| Histogram | Day 34 | 214.62 − 159.23 = 55.39 |
MACD with standard settings needs 34 closes before all three parts exist, and many more before the values stop depending on where the calculation started.
A worked example: the bullish cross on day 52
| Day | Close | 12-period EMA | 26-period EMA | MACD line | Signal line | Histogram |
|---|---|---|---|---|---|---|
| 50 | 24,505.45 | 24,459.93 | 24,629.59 | −169.67 | −134.56 | −35.11 |
| 51 | 24,628.95 | 24,485.93 | 24,629.55 | −143.62 | −136.37 | −7.25 |
| 52 | 24,799.05 | 24,534.10 | 24,642.10 | −108.00 | −130.70 | +22.70 |
| 53 | 24,898.00 | 24,590.09 | 24,661.06 | −70.97 | −118.75 | +47.78 |
The MACD line was still below zero on day 52, so the 12-period EMA was still below the 26-period EMA. The cross above the signal line showed that the gap between them was closing fast. The MACD line crossed zero four sessions later, on day 56, at +2.50.
The three parts of MACD
| Part | What it shows | What traders watch |
|---|---|---|
| MACD line | The gap between the fast and slow EMAs, in points | Its direction, and crosses of zero |
| Signal line | A smoothed version of the MACD line | Crosses with the MACD line |
| Histogram | The gap between the MACD line and the signal line | Its sign, and whether the bars are growing or shrinking |
The MACD line and the zero line
The MACD line is positive when the 12-period EMA is above the 26-period EMA, which happens when recent closes have been higher than older ones. A cross above zero is the moment the fast EMA moves above the slow one, the same event as a 12/26 EMA crossover. A cross below zero is the reverse. The zero line is therefore a slow trend signal: on the model series, MACD crossed below zero on day 41, 9 sessions after the high, and above it on day 56, 12 sessions after the low.
The signal line
The signal line is a 9-period EMA of the MACD line, so it trails the MACD line. When the MACD line crosses above it, the gap between the averages is growing faster than its recent average; when it crosses below, the gap is shrinking. Signal-line crosses come sooner than zero-line crosses and more often.
Reading MACD
| Signal | What it shows | Usual reading |
|---|---|---|
| MACD crosses above the signal line | Momentum turning up | Bullish |
| MACD crosses below the signal line | Momentum turning down | Bearish |
| MACD crosses above zero | The 12-period EMA moves above the 26-period EMA | Uptrend confirmed |
| MACD crosses below zero | The 12-period EMA moves below the 26-period EMA | Downtrend confirmed |
| Histogram bars growing | Momentum increasing | The move is strengthening |
| Histogram bars shrinking | Momentum fading | A signal-line cross may follow |
Crosses above and below zero
Where a signal-line cross happens changes how traders read it.
| Cross | Usual reading | On the model series |
|---|---|---|
| Bullish, with MACD above zero | An uptrend resuming after a pause | None |
| Bullish, with MACD below zero | A fall slowing: the weaker kind of buy signal | Day 52, at −108.00 |
| Bearish, with MACD above zero | An uptrend slowing: the weaker kind of sell signal | Day 37, at 141.09 |
| Bearish, with MACD below zero | A downtrend resuming after a pause | None |
Both crosses on the model series were of the weaker kind, because each came soon after a turn, before the averages had crossed. The bullish cross on day 52 was followed by a zero-line cross four sessions later; the bearish cross on day 37 by one four sessions after it, on day 41. A rule that waits for both signals trades later and less often, and avoids crosses that are not followed through.
The sequence on the model series
| Event | Day | Close | Reading | Sessions after the turn |
|---|---|---|---|---|
| Price high | 32 | 25,500.00 | ||
| MACD line peaks | 34 | 25,432.65 | MACD 214.62 | 2 |
| Bearish signal-line cross | 37 | 24,938.05 | Histogram −22.95 | 5 |
| MACD crosses below zero | 41 | 24,483.65 | MACD −23.28 | 9 |
| Price low | 44 | 24,158.55 | Histogram −129.41, its lowest | |
| Histogram turns up | 45 | 24,181.20 | Histogram −126.78 | 1 |
| MACD line bottoms | 48 | 24,272.45 | MACD −190.77 | 4 |
| Bullish signal-line cross | 52 | 24,799.05 | Histogram +22.70 | 8 |
| MACD crosses above zero | 56 | 24,933.90 | MACD +2.50 | 12 |
The order is the same at both turns: the price turns first, then the histogram, then the MACD line, then the signal-line cross, then the zero-line cross. Each step is later and more reliable than the one before. The bearish cross came 561.95 points below the high and the zero-line cross 1,016.35 points below it; the bullish cross came 640.50 points above the low and the zero-line cross 775.35 points above it.
The MACD histogram
The MACD histogram is the MACD line minus the signal line, drawn as bars above and below zero. Thomas Aspray added it in 1986 to give earlier warning of crosses. Because the signal line is an average of the MACD line, the histogram measures how fast the MACD line is moving away from its own average. It changes sign exactly when the two lines cross.
On the model series the histogram's lowest bar, −129.41, came on day 44, the day of the price low. From day 45 the bars shrank for seven sessions in a row, from −126.78 to −7.25, before turning positive on day 52. A trader watching the histogram saw momentum stop falling seven sessions before the lines crossed.
Two readings of the histogram are common:
- Shrinking bars. Several shrinking bars in a row show momentum fading. Some traders tighten a trailing stop when the histogram shrinks for three bars in a row, rather than waiting for the cross.
- Peaks and troughs. A histogram trough that is shallower than the previous one, while the price makes a lower low, is an early form of divergence.
The histogram is also the noisiest part of MACD. It turns often in sideways markets, and a single shrinking bar means little.
Reading the model series with MACD
| Phase | What MACD did | What it said |
|---|---|---|
| Days 26 to 33 | The MACD line rose from 95.76 to 212.70; no signal line yet | Momentum building in the rally |
| Days 34 to 36 | The histogram shrank from 55.39 to 8.08 while the price stayed near the high | Momentum fading at the top |
| Days 37 to 51 | The histogram stayed negative, lowest at −129.41 on day 44; the MACD line was below zero from day 41, lowest at −190.77 on day 48 | The fall, then its slowing |
| Days 52 to 72 | The histogram stayed positive, between 22.70 and 82.99; the MACD line was above zero from day 56 and ended at 236.92 | The recovery |
MACD is sensitive to single large closes. On day 52 the 170.10-point rise moved the MACD line by 35.62 points, from −143.62 to −108.00, and the histogram by 29.95, enough to turn it positive. A day of the same size in the middle of a calm trend moves the lines just as much, which is one reason a single bar or a single cross carries little weight on its own.
MACD settings
| Setting | Character | Common use |
|---|---|---|
| (12, 26, 9) | The standard | Daily and intraday charts |
| (8, 17, 9) | Faster | Short-term trading, earlier signals |
| (5, 35, 5) | Wide gap between the averages, fast signal line | More sensitive to turns |
| (19, 39, 9) | Slower | Longer trends, fewer signals |
On the model series the settings gave these signals:
| Setting | Signal line from | Signal-line crosses | Zero-line crosses |
|---|---|---|---|
| (12, 26, 9) | Day 34 | Bearish day 37, bullish day 52 | Down day 41, up day 56 |
| (8, 17, 9) | Day 25 | Bullish day 26, bearish day 36, bullish day 50 | Down day 39, up day 54 |
| (5, 35, 5) | Day 39 | Bullish day 49 | Down day 40, up day 53 |
| (19, 39, 9) | Day 47 | Bullish day 54 | Down day 44, up day 57 |
The faster (8, 17, 9) setting crossed one session earlier at the top and two sessions earlier at the bottom, and added a cross on day 26 at the start of the rally. The slower settings need more history: (19, 39, 9) had no signal line until day 47, after the low. The (5, 35, 5) setting crossed zero earliest after the low, on day 53, because its 5-period fast average reacts quickly.
There is no best setting. A setting tuned until it catches the past turns of one instrument usually catches fewer on the next stretch of data. Choose a setting, test it with costs over several years and on more than one instrument, and keep it unless something changes in how the market trades, not because of the last few signals.
MACD divergence
MACD divergence is a disagreement between the price and the MACD line or histogram. In a bearish divergence the price makes a higher high while MACD makes a lower high: the fast average is pulling away from the slow one less strongly than on the last push. In a bullish divergence the price makes a lower low while MACD makes a higher low.
Divergence warns that momentum is fading; it does not time the turn. A trend can produce two or three divergences before it reverses, and some never reverse at all. Traders who trade divergences wait for a price trigger, such as a break of the last swing low or high, or for a signal-line cross, and set a stop beyond the extreme.
MACD has no upper or lower bound, which makes its divergences different from those on RSI. A lower MACD peak can come simply from a slower, steadier rise in which the averages stay closer together, without any loss of trend. Judging two MACD peaks also depends on the price level: a peak of 200 points means less at 26,000 than at 20,000. Divergences on the histogram turn up more often, and give more false warnings, than divergences on the MACD line.
MACD is measured in points
The MACD line is a difference between two prices, so it is measured in the instrument's own points or rupees, and its size depends on the price level and volatility.
| Instrument | Level | The same 0.94% gap between the averages |
|---|---|---|
| Nifty | 25,193 | About 237 points |
| Bank Nifty | 56,000 | About 527 points |
| A stock | ₹1,400 | About ₹13 |
A MACD of 237 is large for Nifty and small for Bank Nifty, and it is not comparable with a stock's ₹13. Even on one index, a MACD reading from five years ago, when the index stood lower, is not comparable with today's.
The PPO divides the gap by the slower average and states it in percent. On day 72 of the model series it is 236.92 ÷ 25,192.47 × 100 = 0.94%. Use the PPO to compare momentum across stocks, across indices or across long periods. Zero-line crosses of the PPO come on the same days as MACD's, because dividing by the slow average does not change the sign of the gap; signal-line crosses can differ by a session when the price level changes a lot.
MACD on intraday charts
The NSE equity and F&O session runs from 9:15 am to 3:30 pm, 375 minutes, so the standard settings cover very different spans on different charts:
| Chart | 12 periods | 26 periods | Values before the first histogram bar |
|---|---|---|---|
| 5-minute | 60 minutes | 130 minutes | 34 candles, about 2 hours 50 minutes |
| 15-minute | 3 hours | 6½ hours, just over one session | 34 candles, about 1⅓ sessions |
| 60-minute | About 2 sessions | About 4 sessions | 34 candles, about 5 sessions |
| Daily | About 2½ weeks | About 5 weeks | 34 sessions |
| Weekly | About 3 months | About 6 months | 34 weeks, about 8 months |
On weekly charts signals are rare, a few a year, so positional traders often take direction from the weekly MACD and timing from the daily one.
Two points matter on Indian indices:
- The opening gap. When Nifty opens far from the previous close, both EMAs jump at once, the fast one more, and the MACD line can leap in the first candle. Some intraday traders ignore the first 15 minutes of signals.
- Continuity across sessions. Platforms carry the EMAs from one session to the next, so the morning's MACD still reflects the previous afternoon. That is useful for direction and less so for the exact level of the first readings.
MACD on Nifty, Bank Nifty, stocks and options
- Index or futures. Read MACD on the Nifty or Bank Nifty index, or on near-month futures. A continuous futures chart jumps at each monthly roll unless the data is adjusted, and the jump passes into both EMAs.
- Options. An option's price falls with time decay and moves with implied volatility, so MACD on the option's own chart mostly tracks decay. Read MACD on the underlying and trade the option on that view.
- Stocks. Use adjusted data around splits and bonus issues, or the averages will show a false collapse. Compare momentum across stocks with the PPO, not with MACD.
MACD with other tools
| Pair MACD with | Why |
|---|---|
| A trend filter, such as the 200-day average | Takes bullish crosses only in a long-term uptrend |
| ADX | Skips crossovers when the market is not trending, where MACD whipsaws |
| RSI | MACD gives the direction of momentum, RSI its extremes |
| Support and resistance | A cross at a known level carries more weight than one in mid-range |
| A volatility measure such as ATR | Sets stops in points that suit the market's movement |
MACD compared with RSI
| MACD | RSI | |
|---|---|---|
| Built from | Two exponential moving averages | Average gains and average losses |
| Range | Unbounded, in points | 0 to 100 |
| Comparable across instruments | No; use the PPO | Yes |
| Best at | Direction and changes of momentum | Overbought and oversold readings, ranges in trends |
| Weakness | Late signals and whipsaws in ranges | Stays at extremes in strong trends |
| Model series, after the high | Bearish cross on day 37 | Crossed below 50 on day 37 |
| Model series, after the low | Bullish cross on day 52 | Crossed above 50 on day 52 |
On the model series MACD's signal-line crosses and RSI's crosses of 50 fell on the same sessions. Both are built from the same closes, and in a clean trend change they usually agree; they disagree most in sideways markets and in strong trends.
A short MACD reading routine
- Check the zero line. Above zero, the 12-period EMA is above the 26-period EMA and the medium-term trend is up; below zero, it is down.
- Check the signal line. A cross shows the latest change in momentum. Note whether it came above or below zero.
- Read the histogram. Growing bars mean momentum is building; several shrinking bars in a row mean it is fading, often before the next cross.
- Look for disagreement. A higher high in price with a lower MACD peak, or a lower low with a higher MACD trough, warns that the move is losing force.
- Confirm with the price. A cross or a divergence is a reason to look, not to trade. A break of a swing high or low, a known level or a trend filter decides whether there is a trade.
- Check the history. On a new chart, make sure at least 34 periods, and preferably several times more, sit behind the first reading you use.
The limits of MACD
- It lags. It is built from moving averages of past closes. On the model series its signal-line crosses came 5 and 8 sessions after the turns.
- It whipsaws in ranges. In a sideways market the lines cross back and forth, and each cross is a false signal.
- It is measured in points. Its values cannot be compared across instruments or across long periods of one instrument.
- Gaps distort it. A large opening gap moves both EMAs at once and can jolt the MACD line on intraday charts.
- It is not a forecast. MACD describes momentum that has already happened.
Common mistakes
- Trading every signal-line cross. In a sideways market most crosses are noise. Use a trend or range filter.
- Comparing MACD values across stocks. Use the PPO for comparisons.
- Reading MACD on an option's chart. Time decay dominates the option's price.
- Ignoring where the cross happens. A bullish cross far below zero in a downtrend is weaker than one near or above zero.
- Using too little history. With standard settings the histogram needs 34 closes to start and many more to settle.
- Changing the settings after each loss. A setting fitted to recent signals rarely holds on the next ones.
Using MACD in a trading strategy
MACD appears in four common roles:
- Trend following. Enter on a bullish signal-line cross when MACD is above zero and exit on the opposite cross, or on the zero-line cross for slower trading. Rules, worked numbers and exits are set out in the MACD trend following strategy.
- Filter. Take long setups from another strategy only when MACD is above zero, or only when the histogram is positive.
- Exit warning. Tighten a trailing stop when the histogram shrinks for several bars in a row.
- Regime check. Combine MACD with ADX or a long moving average to skip crossovers when the market is not trending.
MACD is one of several indicators built from moving averages; the technical indicators guide compares it with the others used in rule-based strategies.
MACD in QuantPower
In the option strategy builder, MACD on the underlying can be used in indicator-based entry and exit conditions, together with price levels, moving averages and time windows, and the trade can be an option, a spread or a futures position. Test the rules in backtesting on five years of 1-minute data, then run them on live prices in paper trading before deploying them through your broker.
Start your free trial
Connect your broker, build a strategy and test it on paper before a single live order goes out.
Frequently asked questions
How is MACD calculated?
Subtract the 26-period EMA of the closes from the 12-period EMA to get the MACD line. Take a 9-period EMA of the MACD line for the signal line, and subtract the signal line from the MACD line for the histogram. On day 52 of the model series that gives −108.00, −130.70 and +22.70.
What does MACD above zero mean?
That the 12-period EMA is above the 26-period EMA, so recent closes have been higher than older ones. A cross above zero is the same event as the 12-period EMA crossing above the 26-period EMA.
What is the MACD histogram?
The MACD line minus the signal line, drawn as bars. It is positive when the MACD line is above the signal line, and its bars shrink when momentum fades, often several sessions before the lines cross.
Can MACD be compared across stocks?
Not directly, because it is measured in points and depends on the price level. The percentage price oscillator divides the gap between the averages by the slower average, which makes the values comparable.
Can MACD be used for options?
Read MACD on the Nifty or Bank Nifty chart, or on the futures, and trade options on that view. MACD on an option's own price chart mostly reflects time decay and is less useful.
What is MACD divergence?
A disagreement between the price and MACD, such as a higher high in price with a lower high in the MACD line. It warns that momentum is fading and is usually traded only after a price trigger or a signal-line cross.
Related guides
- MACD trend following strategy: trend rules built on MACD crosses
- Moving averages: how the EMAs inside MACD work
- RSI indicator: momentum from average gains and losses
- Technical indicators: the common indicators side by side
- Option strategy builder: MACD in entry and exit conditions
Sources
- Appel, G. (2005). Technical Analysis: Power Tools for Active Investors. FT Prentice Hall
- Aspray, T. (1986). Fine-tuning the MACD. Technical Analysis of Stocks & Commodities, 4(4)
- Murphy, J. J. (1999). Technical Analysis of the Financial Markets. New York Institute of Finance
- NSE: trading hours for the equity and equity derivatives segments
