Skip to content

What Is MACD and How to Use It (Beginner’s Practical Guide)

Learn what MACD is, how to calculate it in Python, and how to spot false signals - a practical guide for beginners doing AI-powered data analysis.

7 min readBeginner

You take a MACD crossover signal. Price ticks your way for two bars, then reverses. You exit at a loss. Ten minutes later another crossover fires – same direction. This time you skip it, and of course, that’s the one that would have paid.

That whipsaw pattern is the reason most traders quietly abandon MACD after a month. It’s not that the indicator is broken. It’s that the standard tutorials skip the parts that actually determine whether it works – the math behind the lag, when the default settings fail, and how to interpret the output without eyeballing a chart. This guide covers those parts, with a Python calculation you can run on any CSV of prices.

Why the usual MACD explanations fall short

Every trading blog opens the same way: MACD stands for Moving Average Convergence Divergence, it has three components, buy on bullish crossover. That’s technically correct and practically useless, because it treats MACD as a magic signal generator when it’s really a lag-heavy transformation of past prices.

Here’s the honest framing. Because both the MACD line and the signal line are derived from smoothed historical price series, the indicator may react to price movements with delay, causing trading signals to appear only after a trend has already begun. That delay is not a bug. It’s the whole design – MACD trades responsiveness for noise reduction. The failure mode is when there’s no trend to detect: MACD can generate false signals when the price moves sideways or in a range-bound market, as it may produce crossovers that do not reflect the true trend direction.

So the real question isn’t “what is MACD.” It’s: when does the signal mean something, and how do you filter out the rest?

The three numbers, and what they actually do

MACD has exactly three moving parts. Here’s what each one is doing under the hood, not just what it’s called:

  • MACD linecalculated by subtracting the 26-period Exponential Moving Average (EMA) from the 12-period EMA. When the short-term average pulls away from the long-term one, this number grows. That’s momentum, quantified.
  • Signal linethe moving average of the MACD Line, usually a 9-period exponential moving average. This is an EMA of an EMA difference, which is why it lags the MACD line by roughly 4-5 bars. That gap is where crossovers come from.
  • Histogram – MACD minus Signal. When the histogram is above zero, it signifies that the MACD line is above the signal line, indicating bullish momentum. Conversely, when the histogram is below zero, the MACD line is below the signal line, suggesting bearish momentum. The histogram is the earliest of the three signals because it moves before the crossover completes.

Defaults are 12, 26, 9. MACD was developed by Gerald Appel in 1979 for stock analysis, and those numbers were tuned for daily equity charts of that era. They’re the default in pandas_ta, TradingView, and almost every charting tool – but “default” and “optimal” are different words.

How to use MACD: calculate it yourself in Python

Reading MACD off a broker’s chart is fine. Calculating it yourself is better, because you see exactly where the numbers come from and you can feed them into any downstream analysis – an LLM prompt, a screener, a backtest.

Here’s the minimum working version using pandas:

import pandas as pd
import yfinance as yf

# Grab 1 year of daily closes for any ticker
df = yf.Ticker('AAPL').history(period='1y')[['Close']]

# MACD math
fast = df['Close'].ewm(span=12, adjust=False).mean()
slow = df['Close'].ewm(span=26, adjust=False).mean()
df['macd'] = fast - slow
df['signal'] = df['macd'].ewm(span=9, adjust=False).mean()
df['histogram'] = df['macd'] - df['signal']

# Flag crossovers
df['cross'] = 0
df.loc[(df['macd'] > df['signal']) & (df['macd'].shift() <= df['signal'].shift()), 'cross'] = 1 # bullish
df.loc[(df['macd'] < df['signal']) & (df['macd'].shift() >= df['signal'].shift()), 'cross'] = -1 # bearish

print(df.tail(10))

Two things to notice. First, adjust=False matters – it makes pandas match the EMA formula that TradingView and MetaTrader use. Leave it out and your values drift from every chart you’re comparing against. Second, the cross column is where you’d start filtering: instead of trading every crossover, you’d add a condition like “only if histogram magnitude > some threshold” or “only if 50-day trend agrees.”

The signals nobody teaches you to filter

Once you have MACD values in a dataframe, the interesting work starts. Three specific traps most beginners walk into:

1. Sideways-market whipsaws. In a ranging market you’ll see 4-6 crossovers in a week, all fake. The fix isn’t more MACD – it’s a regime filter. Compute a 14-day ADX or just the standard deviation of returns; if it’s below a threshold, ignore all MACD signals for that period.

2. No overbought/oversold anchor.The MACD does not have concrete overbought or oversold levels like some other indicators, which can make it more challenging to identify potential price reversals. RSI has 70/30. MACD has nothing. Traders sometimes invent zero-line rules (“only long above zero”), but no documentation validates them – they’re heuristics, treat them as such.

3. Timeframe mismatch.The indicator tends to lag on the M1-M15 time frames, leading to more false signals during flat markets. It is less effective for scalping and requires confirmation from other tools. If you’re trading 5-minute crypto candles with default 12/26/9, you’re using a 1979 daily-chart tool on a completely different distribution of price data. Either adjust the parameters or use a different indicator.

Pro tip: Before trusting any crossover, check whether the histogram is expanding or contracting across the last 3 bars. A crossover with a shrinking histogram usually reverses within a few bars. A crossover with an expanding histogram tends to hold. This one filter cuts most whipsaw entries.

Feeding MACD output to an LLM for interpretation

This is the part no trading blog covers, because they’d rather sell you a broker account. Once your dataframe has MACD, signal, and histogram, you can hand the last N rows to Claude or GPT and ask for a plain-English read.

A prompt that works:

You are analyzing MACD output for a beginner.
Here are the last 20 daily bars for TICKER:
{df[['Close','macd','signal','histogram']].tail(20).to_string()}

Answer:
1. Is momentum currently bullish, bearish, or unclear?
2. Is the histogram expanding or contracting?
3. Any bearish/bullish divergence vs. price?
4. What would invalidate your read?

The LLM won’t predict price – nothing does. But it’ll surface things you’d miss scrolling a chart, like a bearish divergence where the stock reaches a new high but MACD doesn’t, which signals a potential sell-off. Ask it to explain why, and you’re learning technical analysis while you work. That’s a use case competitor tutorials can’t offer because they were written before this workflow existed.

Quick FAQ

What are the best MACD settings for beginners?

Stick with 12/26/9 on daily charts. It’s the tested default. Don’t tune parameters until you’ve traded the standard version long enough to understand what “normal” looks like.

Can MACD predict trend reversals?

Not really – it can flag them after momentum has already shifted. The one exception is divergence: if price makes a new high but the MACD line doesn’t, that’s often (not always) an early warning that buyers are running out of energy. Treat it as a hypothesis to check with other tools, not a signal to short.

Is MACD useful outside of trading?

Yes, though it’s rarely used that way. The math – a smoothed difference between two exponential moving averages – works on any noisy time series where you want to spot trend changes: server load, ad-spend efficiency, weekly signup counts. Same formula, different data.

Next step: pull one year of data for a ticker you actually follow, run the Python snippet above, and mark every crossover on the chart. Count how many led to a real 5%+ move within 10 bars, versus how many reversed inside 3 bars. That single exercise teaches more than any tutorial – including this one.