Moving Average Convergence Divergence (MACD)
Calculate the Moving Average Convergence Divergence (MACD) indicator for a given price series.
The Moving Average Convergence Divergence (MACD) is a trend-following momentum indicator that shows the relationship between two moving averages of a security’s price. It consists of the MACD line and its signal line; their difference is the MACD histogram.
The formula is as follows:
\[\text{MACD Line} = \operatorname{EMA}(\text{Close},\; \text{short\_window}) - \operatorname{EMA}(\text{Close},\; \text{long\_window})\] \[\text{Signal Line} = \operatorname{EMA}(\text{MACD Line},\; \text{signal\_window})\]The MACD line crossing its signal line is the usual trigger, and the MACD crossing zero means the short average has crossed the long one. Because the MACD is a price difference, its level scales with the share price and cannot be compared across stocks; the Percentage Price Oscillator divides by the long average for that. Both lines lag price, so crossovers come late in fast reversals.
Also known as: MACD, momentum indicator.
Moving Average Convergence Divergence (MACD) in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_moving_average_convergence_divergence as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
tickers=["MSFT"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2024-10-01",
end_date="2025-12-31",
)
toolkit.technicals.get_moving_average_convergence_divergence().xs("MSFT", level=1, axis="columns").tail(5)
Or, after setting up the Finance Toolkit MCP, ask:
How did Microsoft's MACD line move against its signal line from 24 to 31 December 2025, based on prices from October 2024?
Which returns:
| Date | MACD Line | Signal Line |
|---|---|---|
| 2025-12-24 | -3.02 | -4.8167 |
| 2025-12-26 | -2.5054 | -4.3544 |
| 2025-12-29 | -2.122 | -3.908 |
| 2025-12-30 | -1.7673 | -3.4798 |
| 2025-12-31 | -1.7752 | -3.1389 |
Parameters
get_moving_average_convergence_divergence accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The time period to consider for historical data. Can be “intraday”, “daily”, “weekly”, “monthly”, “quarterly” or “yearly”. Defaults to “daily”. | "weekly" |
close_column | str | The column name for closing prices in the historical data. Defaults to “Adj Close”. | "Close" |
short_window | int | The number of periods for the shorter moving average. Defaults to 12. | 5 |
long_window | int | The number of periods for the longer moving average. Defaults to 26. | 35 |
signal_window | int | The number of periods for the signal line. Defaults to 9. | 5 |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
growth | bool | Whether to calculate the growth of the MACD and signal values. Defaults to False. | True |
lag | int | list[int] | The lag to use for the growth calculation. Defaults to 1. | 4 |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |