MACD Indicator: Signal Lines, Crossovers and Whipsaws

Table of Contents

    A stock can keep closing higher as its MACD histogram turns negative. The two lines behind the histogram explain how that happens. A different problem occurs when the stock trades in a tight range and those lines keep crossing. Both patterns appear in the worked examples below.

    What Is MACD?

    Moving average convergence divergence (MACD) measures the gap between two exponential moving averages (EMAs). Gerald Appel developed the indicator. In the common MACD (12, 26, 9) setting, the fast and slow EMAs use 12 and 26 bars of closing prices as their respective spans. A third EMA smooths the resulting gap over a 9-bar span to produce the signal line. Thomas Aspray plotted the difference between MACD and its signal line as a histogram.[1][2][3]

    A bar is one observation interval. On a daily stock chart, each completed trading session supplies one close. On an hourly chart, the same settings count hourly bars. With closes in dollars per share, MACD, its signal line and the histogram are all in dollars per share.[4]

    MACD, Signal Line and Histogram Formulas

    The three values on bar t
    MACD = 12-bar price EMA − 26-bar price EMA
    Signal = 9-bar EMA of MACD
    Histogram = MACD − Signal

    On each update, move the previous EMA a fraction of the way toward the current input. That fraction is 2 / (N + 1) for span N. The 12-bar and 26-bar EMAs move 2 / 13 and 2 / 27 of the way toward the new close, respectively. The signal moves 1 / 5 of the way toward the new MACD value. Older observations can still influence an EMA because each update carries forward part of the previous value.[2][5][6]

    How to Read the Two Crossovers

    MACD crosses zero

    The fast and slow price EMAs switch order. A move from negative to positive means the fast EMA has moved above the slow EMA. MACD is zero when the price EMAs are equal.

    MACD crosses its signal line

    MACD and its signal switch order. A histogram that changes from positive to negative means MACD has moved below its signal line. The histogram is zero when these two lines are equal.

    A shrinking positive histogram means MACD is getting closer to its signal from above. The signal can rise faster than MACD and narrow the gap while both are still rising. When counting crossovers on completed bars, use the sign of the unrounded value. A touch of zero followed by a return to the same side leaves the two lines in their original order.[2][4]

    How Much Price History Does MACD Need?

    For the calculations below, start each EMA with a seed equal to the arithmetic mean of its first full span. A first-close EMA seed can give different early values when the opening observations vary. The first 100 closes in both examples are $100, so the price EMAs from the two methods agree whenever both values are available. Use one completed close per session, in chronological order.[5][6]

    1. Average the first 12 closes to seed the fast EMA on bar 12. Update it from bar 13 onward.
    2. Average the first 26 closes to seed the slow EMA on bar 26. Subtract that seed from the fast EMA already calculated on bar 26 to get the first MACD. Update the slow EMA from bar 27 onward.
    3. Average MACD values from bars 26 through 34 to seed the signal on bar 34. Subtract that signal from bar 34’s MACD to get the first histogram. Update the signal from bar 35 onward.

    Bar 34 is the first complete result with these seeds. For a live data comparison, the warm-up is the earlier history used to reduce the effect of starting choices. Two 26-bar EMAs fed the same closes retain about 13.5% of their initial gap after 26 updates, because (25 / 27)26 is about 0.135. MACD inherits the seed effects of both price EMAs, and the signal smooths that series in turn. Extend the input history until the MACD, signal and histogram agree at the precision you need, checking the sign near any cross you plan to interpret. For exact replication, match the inputs and starting rules.[5][7]

    Worked Examples: A Rising Stock and a Choppy Range

    Both hypothetical paths begin with 100 daily closes at $100 per share. Apply the seeds above and calculate at the end of each session. At bar 100 both price EMAs are exactly $100 and all three MACD series are zero. Both paths then close at $102 on bar 101.

    Calculate MACD on bar 101

    The fast EMA moves to $100 + (2 / 13) × $2, about $100.307692. The slow EMA moves to $100 + (2 / 27) × $2, about $100.148148. Subtracting gives MACD of about 0.159544. The signal rises from zero by one-fifth of that value to about 0.031909. The histogram is about 0.127635. All values are in dollars per share. Carry full precision through the calculations.

    The stock keeps rising as the histogram crosses below zero

    In the first path, the stock gains $2 each session from bar 101 through 108, reaching $116. From bar 109 through 124 it gains $0.25 each session, reaching $120. The table shows selected completed bars under the same 12, 26, 9 settings.

    Hypothetical rising path (USD per share)
    Bar Close MACD Signal Histogram
    108 116.00 3.3839 1.7885 1.5954
    109 116.25 3.8001 2.1908 1.6093
    110 116.50 4.1028 2.5732 1.5296
    120 119.00 4.1660 4.1645 0.0015
    121 119.25 4.0594 4.1435 −0.0841
    124 120.00 3.7276 3.9867 −0.2591

    From bar 109 to 110 the signal rises faster than MACD, so the positive histogram shrinks. On bar 121, the histogram turns negative as MACD falls below its signal. The close is up $0.25, both price EMAs rise and the fast EMA still exceeds the slow by about $4.06. The negative histogram and the positive MACD describe two different gaps.

    In the range, the signal-line crosses keep reversing

    Reset to the same first 100 closes at $100. In this path, the stock alternates between $102 on odd bars and $98 on even bars from 101 through 124. The table shows the first six sessions in that range.

    Hypothetical choppy path (USD per share)
    Bar Close MACD Signal Histogram
    101 102.00 0.1595 0.0319 0.1276
    102 98.00 −0.0364 0.0183 −0.0546
    103 102.00 0.1297 0.0405 0.0891
    104 98.00 −0.0608 0.0203 −0.0811
    105 102.00 0.1097 0.0381 0.0715
    106 98.00 −0.0770 0.0151 −0.0922

    At bar 102, MACD falls to about −0.0364 and its signal stays slightly positive. The resulting negative histogram turns positive again the next session. The reversal repeats on every bar from 102 through 124, giving 23 sign changes while prices stay within the same $4 range. That rapid back-and-forth is a whipsaw. This example shows one way whipsaws arise. The actual frequency depends on the price path and settings.[3]

    What Changes When You Shorten the Signal Period?

    Keep the two price EMAs and the rising price path. Use a five-bar signal EMA with a seed equal to the mean of MACD values from bars 26 through 30. Its update puts one-third of the weight on the current MACD, versus one-fifth for a nine-bar signal. The five-bar histogram is about +0.0252 on bar 117 and −0.0364 on bar 118. It crosses down three sessions earlier than the nine-bar version on this path. The crossover dates depend on the series being smoothed.[4][5]

    MACD Divergence and How It Compares With RSI

    In a bearish price–MACD divergence, price makes a higher swing high while MACD makes a lower high at the corresponding swing. A bullish divergence pairs a lower price swing low with a higher MACD low. A comparison between MACD and the histogram is a separate observation. Specify the two series and compare swings on the same interval. If a swing definition requires later bars to confirm a high or low, include that delay when testing a rule. A divergence can persist while prices continue in the same direction.[2][4]

    Relative strength index (RSI) puts smoothed gains and losses on a 0–100 scale. MACD uses the price difference between two averages and has no fixed bounds. A MACD of +2 on a dollar-priced stock means a $2-per-share spread between the EMAs. That spread can be large for one stock and small for another.[3][4]

    How to Reproduce MACD in Excel

    Put the closes in chronological order and use a column for each price EMA, MACD, the signal and the histogram. Seed each average with AVERAGE on the complete ranges above. From the following row in each EMA column, add the smoothing factor times the gap between the current input and the previous EMA value. Keep unavailable early values blank. Check the seed ranges for missing observations because Excel’s AVERAGE skips blank cells.[5][9]

    If you compare the result with an add-in or chart, match the indicator variant and the price and date range it uses. MarketXLS, for example, lists standard MACD, a version with a selectable moving-average type and a fixed 12/26 version. Its indicator list establishes which tools are offered. Check the chosen implementation’s starting rules and inputs to explain any differences.[4][8]

    Common Mistakes With MACD

    • Assuming the same labels guarantee the same initialization. Platforms can seed the price averages on different dates, use different smoothing factors or calculate from additional bars before the visible chart.[5][6]
    • Mixing price series or bar definitions. Match the interval, session cutoff and choice of raw or adjusted closes. Check for missing observations on actual trading days. An exchange closure contributes no observation to a daily close series.[4][6][8]
    • Counting a cross before the bar closes. An intrabar value can change before the final close. Use completed bars if the rule is defined at the close. A rule that trades on the signal also needs a separately specified execution time and price.[4]

    Limitations of MACD

    Every value comes from prices already observed and from averages that carry some of their prior values forward. Those averages can respond slowly to a turn. In a range, a string of crosses can carry little information about the direction of the next sustained move. The 12, 26, 9 convention is a comparison point. Assess a trading rule with its own price data, signal and execution timing, costs and separate evaluation period.[2][3][7]

    Frequently Asked Questions

    Yes. A positive MACD puts the fast price EMA above the slow one. A negative histogram puts MACD below its signal. Both statements hold on bar 121 in the rising example.[4]

    With the arithmetic-mean seeds above, the first MACD is ready at bar 26. The signal needs nine available MACD values, so the signal and histogram begin on bar 34. An implementation can delay its displayed MACD to align all three outputs.[5]

    The numbers count bars in the selected timeframe. With weekly data, the price EMA spans are 12 and 26 weeks and the signal uses a nine-week EMA of the weekly MACD.[4]

    Sources

    1. Gerald Appel, Technical Analysis: Power Tools for Active Investors, 2005. Chapter 8 and The Basic Construction of the MACD Indicator.
    2. Thomas Aspray, Trading Basics – MACD (Convergence/Divergence) – Part 1, May 2008.
    3. Fidelity Learn, MACD Technical Indicator Guide.
    4. TradingView, Moving average convergence divergence indicator, calculation, divergence and settings.
    5. TA-Lib v0.6.4, EMA initialization and MACD implementation.
    6. pandas 2.3.3, Exponentially weighted calculations, span, adjustment and missing values.
    7. NIST/SEMATECH e-Handbook of Statistical Methods, EWMA Control Charts and Single Exponential Smoothing.
    8. MarketXLS, Technical Indicators in Excel and Understand splits, dividends, and adjusted prices.
    9. Microsoft Support, AVERAGE function.
    Educational Use

    This article is for general education. The examples use hypothetical share prices.