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, signal line, and MACD histogram.

The formula is as follows:

\[\text{MACD Line} = \text{Short-term EMA} - \text{Long-term EMA}\] \[\text{Signal Line} = \operatorname{SMA}(\text{MACD Line})\]

Also known as: MACD, momentum indicator.

Moving Average Convergence Divergence (MACD) in Python

get_moving_average_convergence_divergence is part of the Technicals module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_moving_average_convergence_divergence as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(tickers=["AAPL", "MSFT"])

toolkit.technicals.get_moving_average_convergence_divergence().xs("AAPL", level=1, axis="columns")

Which returns:

Date MACD Line Signal Line
2026-06-18 1.1803 3.2153
2026-06-22 0.9697 2.7662
2026-06-23 0.5776 2.3285
2026-06-24 0.1664 1.8961
2026-06-25 -1.588 1.1993
2026-06-26 -2.2559 0.5082
2026-06-29 -2.9163 -0.1767
2026-06-30 -2.7926 -0.6999
2026-07-01 -2.2633 -1.0125
2026-07-02 -0.6862 -0.9473

Parameters

get_moving_average_convergence_divergence accepts the following parameters:

  • period (str, optional): The time period to consider for historical data. Can be “daily”, “weekly”, “quarterly”, or “yearly”. Defaults to “daily”.
  • close_column (str, optional): The column name for closing prices in the historical data. Defaults to “Adj Close”.
  • short_window (int, optional): The number of periods for the shorter moving average. Defaults to 12.
  • long_window (int, optional): The number of periods for the longer moving average. Defaults to 26.
  • signal_window (int, optional): The number of periods for the signal line. Defaults to 9.
  • rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
  • growth (bool, optional): Whether to calculate the growth of the MACD and signal values. Defaults to False.
  • lag (int | list[int], optional): The lag to use for the growth calculation.
  • standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. Defaults to 1.
Share