pip install Ta-Lib
python
import talib
python
macd, signal, hist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
python
import talib
import numpy as np
import matplotlib.pyplot as plt
close_prices = np.array([10, 12, 11, 13, 14, 15, 14, 12, 11, 10])
macd, signal, hist = talib.MACD(close_prices)
plt.plot(close_prices, label='Close Prices')
plt.plot(macd, label='MACD Line')
plt.plot(signal, label='Signal Line')
plt.bar(range(len(close_prices)), hist, label='MACD Hist')
plt.legend()
plt.show()