MACD Explained: 12-26-9 Calculated by Hand on 40 Bars, and How Crossovers Tested
MACD is the 12-bar EMA minus the 26-bar EMA, plus a 9-bar EMA of that difference called the signal line. This page calculates every number by hand on 40 real SPY closes and tests the crossover on 10 years of data: bullish crossovers were followed by a +0.98% average 10-day change, but bearish ones were also followed by gains (+0.65%), against +0.53% on an average day.
What MACD is and how it is built
MACD stands for moving average convergence divergence. It is built from three series, and TradingView's help page describes them the same way: the MACD line (a fast moving average minus a slow one), a signal line (a moving average of the MACD line) and a histogram (MACD minus signal).
The conventional settings are 12, 26 and 9, all exponential moving averages (EMAs) of the close. TradingView's page lists the inputs (fast length, slow length, signal length and the type of average) but does not print the defaults in the text we read, so treat 12-26-9 as the common convention, not a rule. Every charting platform lets you change them.
The formulas are: MACD = EMA(12) minus EMA(26). Signal = EMA(9) of the MACD line. Histogram = MACD minus Signal. An EMA gives recent closes more weight: each new EMA equals the old EMA plus a fraction of the gap between the new close and the old EMA. The fraction is 2 divided by (length plus 1), so 2/13 = 0.153846 for the 12-bar EMA, 2/27 = 0.074074 for the 26-bar EMA and 2/10 = 0.2 for the 9-bar signal line.
Because both inputs are lagging averages, MACD can only describe what price has already done. It does not forecast. The rest of this page shows the arithmetic, then tests whether the crossover signal carried any information on one liquid instrument.
| Part | Formula (12-26-9) | What it shows |
|---|---|---|
| MACD line | EMA(12) of close minus EMA(26) of close | Above zero: the fast average is above the slow one. Below zero: the reverse. |
| Signal line | 9-bar EMA of the MACD line | A smoothed version of MACD. Crossing points are the usual trigger. |
| Histogram | MACD minus Signal | Positive when MACD is above the signal line. Its sign flips at each crossover. |
| EMA weight, 12 bars | 2 / 13 = 0.153846 | Share of the newest gap added to the old average each bar. |
| EMA weight, 26 bars | 2 / 27 = 0.074074 | Same, for the slow average. |
| EMA weight, 9 bars | 2 / 10 = 0.2 | Same, for the signal line. |
Step 1: seed the averages from 40 real closes
We used the 40 most recent SPY (S&P 500 ETF) daily closes in the Nasdaq historical data, from 28 September to 20 November 2026. SPY is a US ETF; the data is price only, with no dividends. We chose the latest 40 bars because they were the newest data, not because MACD behaved well on them.
An EMA needs a starting value. The usual method is to seed it with a simple average. The 12-bar EMA starts on bar 12 as the simple average of bars 1 to 12: the 12 closes add to US$9,265.82, and divided by 12 that is 772.152. The 26-bar EMA starts on bar 26 as the average of bars 1 to 26: the sum is US$19,987.53, and divided by 26 it is 768.751.
From then on each bar applies the update. Bar 13 closed at 769.60, so EMA(12) = 772.152 + 0.153846 x (769.60 − 772.152) = 771.759. Bar 27 closed at 754.35, so EMA(12) = 764.404 + 0.153846 x (754.35 − 764.404) = 762.857, and EMA(26) = 768.751 + 0.074074 x (754.35 − 768.751) = 767.684. The MACD line on bar 27 is 762.857 minus 767.684, which is −4.827.
The MACD line cannot exist before bar 26, because the 26-bar EMA does not exist yet. The signal line needs nine MACD values, bars 26 to 34, so it starts on bar 34. That is why 30 bars are not enough to show a full MACD with its signal line, and why this example uses 40.
Step 2: the full table from bar 26 to bar 40
The signal line is seeded the same way: the simple average of the nine MACD values on bars 26 to 34 is −5.941. After that, Signal = old Signal + 0.2 x (MACD − old Signal). On bar 34 the histogram is MACD minus Signal = 0.404, positive, so MACD is above its signal line.
The histogram stays positive on bar 35 (0.595) and turns negative on bar 36, 16 November (−0.185). That is a bearish crossover: the MACD line moved from above the signal line to below it. SPY closed at 739.95 that day. Values are rounded to three decimals for display; a spreadsheet carries full precision, so the last digit can differ.
| Bar (date) | Close | EMA(12) | EMA(26) | MACD | Signal | Histogram |
|---|---|---|---|---|---|---|
| 26 (11-02) | 752.10 | 764.404 | 768.751 | −4.347 | not yet | not yet |
| 27 (11-03) | 754.35 | 762.857 | 767.684 | −4.827 | not yet | not yet |
| 28 (11-04) | 766.81 | 763.465 | 767.620 | −4.154 | not yet | not yet |
| 29 (11-05) | 733.00 | 758.778 | 765.055 | −6.277 | not yet | not yet |
| 30 (11-06) | 735.29 | 755.165 | 762.850 | −7.686 | not yet | not yet |
| 31 (11-09) | 752.69 | 754.784 | 762.098 | −7.314 | not yet | not yet |
| 32 (11-10) | 749.92 | 754.036 | 761.196 | −7.160 | not yet | not yet |
| 33 (11-11) | 759.81 | 754.924 | 761.093 | −6.169 | not yet | not yet |
| 34 (11-12) | 757.12 | 755.262 | 760.799 | −5.537 | −5.941 | 0.404 |
| 35 (11-13) | 754.37 | 755.125 | 760.323 | −5.198 | −5.792 | 0.595 |
| 36 (11-16) | 739.95 | 752.790 | 758.813 | −6.023 | −5.839 | −0.185 |
| 37 (11-17) | 732.44 | 749.659 | 756.860 | −7.201 | −6.111 | −1.090 |
| 38 (11-18) | 730.20 | 746.666 | 754.885 | −8.219 | −6.533 | −1.687 |
| 39 (11-19) | 715.87 | 741.928 | 751.995 | −10.067 | −7.240 | −2.828 |
| 40 (11-20) | 689.81 | 733.910 | 747.389 | −13.479 | −8.488 | −4.992 |
What this example does and does not show
On the table, MACD fell from −4.347 on bar 26 to −13.479 on bar 40, and the histogram widened to −4.992. SPY closed at 689.81 on bar 40, 6.8% below the 739.95 close on the crossover bar (689.81 / 739.95 = 0.9322). A trader who treated the bearish crossover as a sell signal would have been right on this stretch.
One stretch proves nothing. A single example is the easiest way to make an indicator look good, and the next section checks the signal across every crossover in ten years. Notice too what the table says about the delay: the crossover appears on bar 36, after the price had already dropped from about 778 in mid-October to about 740. Moving averages lag by design, and so does MACD.
Test: what happened after 218 crossovers in ten years
We ran the same 12-26-9 calculation on every SPY daily close from 21 November 2016 to 20 November 2026 (2,513 daily rows; one row that Nasdaq lists without volume was removed). A bullish crossover is the histogram moving from zero or below to above zero. A bearish crossover is the reverse. We measured the change in close over the next 10 trading days, ignoring costs and dividends. Each crossover is counted when its bar closes, so no future information is used.
The result: there were 218 signal-line crossovers (109 of each kind), about 22 a year. After bullish crossovers the average 10-day change was +0.98% and 69% of cases were up. After bearish crossovers it was +0.65% and 66% were up. For comparison, the average 10-day change over all days in the same period was +0.53%, and 65% of those windows were up.
Read that carefully. Bullish crossovers did a little better than an average day, which fits the idea that they mark rising momentum. But bearish crossovers were also followed by gains on average, so a short trade on every bearish crossover would have lost money before costs. SPY rose strongly over the period, and a rising asset punishes any rule that sells. The gap between 0.98% and 0.53% is small next to the spread of 10-day returns, and we did not test whether it is statistically reliable. Do not treat it as an edge.
| Setting | Crossovers per year | Reversed within 5 bars | After bullish: avg 10-day / % up | After bearish: avg 10-day / % up | All days: avg 10-day / % up |
|---|---|---|---|---|---|
| 5-35-5 | 35.4 | 48% | +0.75% / 62% | +0.60% / 66% | +0.53% / 64% |
| 8-17-9 | 26.7 | 36% | +0.84% / 64% | +0.57% / 66% | +0.53% / 65% |
| 12-26-9 | 22.1 | 30% | +0.98% / 69% | +0.65% / 66% | +0.53% / 65% |
| 19-39-9 | 18.9 | 35% | +0.20% / 61% | +0.09% / 55% | +0.53% / 64% |
Which MACD settings should you use?
The table above answers the settings question for this one instrument. Faster settings crossed far more often (35 times a year on 5-35-5 against 22 on 12-26-9), and almost half of the 5-35-5 crossovers were reversed within five bars, which is what traders call whipsaws. The slower 19-39-9 set crossed less, but its signals were followed by returns below an average day. None of the four sets produced a clear edge, and we did not search for the best one, because picking the best of many settings on past data mostly finds noise.
The practical lesson is about cost. Each crossover is a trade. At 35 a year, commissions and spread on a stop-and-reverse approach would use up much of the gap between bullish-crossover returns and an average day, which was 0.22 to 0.45 percentage points on the three faster sets. If you use MACD, choose a setting that suits the holding period you actually trade, keep it fixed, and test it on your own instrument with your own costs before risking money. The MACD line crossing zero is another common trigger; we counted 69 zero-line crosses in the ten years, far fewer than the 218 signal crossovers.
Limits of this test and who should skip MACD
The test uses one instrument, SPY, and a single signal rule. Results on single stocks, futures, forex or crypto can differ. It uses daily closes only, ignores transaction costs and dividends, and measures a fixed 10-day window rather than a trade with a stop and target. Past results do not predict future ones.
MACD is a poor fit if you want a precise entry: it lags. It also works worst in sideways markets, where the two averages tangle and the lines cross repeatedly, as the whipsaw column shows. On very short timeframes, the signal on a 1-minute chart arrives after much of the move and spread and slippage take the rest; we did not test intraday data.
If you use the indicator without trusting it as a forecast, treat it as a description of momentum: MACD above zero means the 12-bar average sits above the 26-bar average, nothing more. For the averages underneath it, see our EMA vs SMA guide. This page is educational and is not investment advice.
Frequently asked questions
What are the standard MACD settings?
12, 26 and 9: a 12-bar EMA minus a 26-bar EMA, with a 9-bar EMA of the result as the signal line. These are the common defaults; you can change them on any charting platform.
What is a MACD crossover?
The MACD line crossing the signal line. Crossing up is called bullish and crossing down bearish; the histogram changes sign at the same moment. In our 10-year SPY test the 12-26-9 set produced about 22 crossovers a year.
Does a bearish MACD crossover mean the price will fall?
Not reliably. On SPY from 2016 to 2026, the average 10-day change after a bearish 12-26-9 crossover was +0.65%, and 66% of cases were up. That is one instrument and one rule, so it is not a universal result.
How many bars do you need to calculate MACD by hand?
At least 26 for the MACD line and 34 for the signal line (26 plus 8 more bars to get nine MACD values). This page uses 40.
Is MACD a leading or lagging indicator?
Lagging. It is built from moving averages of past closes, so it confirms movement that has already begun.
Sources
Provider documents behind this page, checked November 23, 2026.