I found the answer in this great post. its not direct implementation but at least the logic is the same and by replacing RSI info with MACDHist you get to the same conclusion. How to implement RSI Divergence in Python

Answer from Sam.H on Stack Overflow
🌐
Aleksandar Haber
aleksandarhaber.com › macd-moving-average-convergence-divergence-of-stock-price-time-series-in-pandas-and-python
6. Accurately Compute MACD (Moving Average Convergence/Divergence) of Stock Price Time Series in Pandas and Python – Fusion of Engineering, Control, Coding, Machine Learning, and Science
In this post, we explain how to compute and how to plot MACD (Moving Average Convergence/Divergence) of Stock Price Time Series in Pandas and Python. This parameter is important for generating the buy/sell signals of stocks, see for example the Wikipedia page.
Discussions

Thinking of automating a trading strat involving ADX, MACD and RSI, what do yall think of strat involving these indicators?
Good luck man. Even doing a general optimisation will overfit these. More on reddit.com
🌐 r/algotrading
104
45
October 6, 2023
I created a divergence indicator (Python)
man this is so clean, you did a great job thanks for sharing More on reddit.com
🌐 r/algotrading
23
54
November 12, 2021
Coding price-RSI divergence?
That might help with the extrema. https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.argrelextrema.html - The idea could look good in backtesting (depending on the quality of the backtest), but the relative maxima and minima will be lagging behind. In other words you will never know if the current bar is a extrema instantly. Depending on your settings it takes X bars more, before its recognisable as extrema. So you probably always miss the (perfect) entry / exit. If you trade crypto, checkout jesse: https://docs.jesse-ai.com/docs/indicators/reference.html#minmax - it offers the detection of extrema already and is a good backtesting framework. More on reddit.com
🌐 r/algotrading
3
7
June 7, 2020
Hidden Powers of Python (3) and final — backtrader
1.5m members in the algotrading community. A place for redditors to discuss quantitative trading, statistical methods, econometrics, programming … More on reddit.com
🌐 r/algotrading
🌐
GitHub
gist.github.com › whittlem › ba1adbc08860e3754b320723df4bd710
Trading using Python - Moving Average Convergence Divergence (MACD) · GitHub
Trading using Python - Moving Average Convergence Divergence (MACD) - movingAverageConvergenceDivergence.py
🌐
AskPython
askpython.com › home › (4/5) macd indicator: python implementation and technical analysis
(4/5) MACD Indicator: Python Implementation and Technical Analysis - AskPython
April 10, 2025 - Whenever the MACD line crosses the signal line upwards, it essentially signals that the stock will have a bullish run. Similarly, when the MACD line crosses the signal line downwards, it signals that the stock price will fall. Now we know that the indicator is about convergence and divergence, ...
🌐
alpharithms
alpharithms.com › home › tutorials › calculating the macd in python for algorithmic trading
Calculating the MACD in Python for Algorithmic Trading - αlphαrithms
April 10, 2023 - Pandas provides a built-in function to its DataFrame class named ewm() which stands for exponentially-weighted mean. This will allow us to calculate the MACD and the Trigger values that will, in turn, provide us with the raw values needed to represent the convergence/divergence.
🌐
GitHub
github.com › xoopsi › macd-divergence-detector
GitHub - xoopsi/macd-divergence-detector: This repository contains Python code for detecting MACD (Moving Average Convergence Divergence) divergences in financial time series data. The code provides functions to calculate MACD ranges, identify local peaks and troughs, and detect both regular and hidden bullish and bearish divergences.
This repository contains Python code for detecting MACD (Moving Average Convergence Divergence) divergences in financial time series data. The code provides functions to calculate MACD ranges, identify local peaks and troughs, and detect both regular and hidden bullish and bearish divergences.
Author   xoopsi
Find elsewhere
🌐
Finxter
blog.finxter.com › home › learn python blog › moving average convergence divergence (macd) – python binance api for crypto trading
Moving Average Convergence Divergence (MACD) – Python Binance API for Crypto Trading - Be on the Right Side of Change
August 2, 2023 - Whenever the MACD > signal, the moving average (EMA in this case) is either converging or diverging from the signal. This can be considered as +1, else 0. A new column ‘Trigger’ can be formed using the NumPy function where(). The np.where() function can be thought of as an if-else condition ...
🌐
Quantified Strategies
quantifiedstrategies.com › python-and-macd-trading-strategy
Python and MACD Trading Strategy: Backtest, Rules, Code, Setup, Performance - QuantifiedStrategies.com
February 9, 2026 - In this article, we are going to backtest a MACD trading strategy using Python: from downloading data from Yahoo Finance and calculating the MACD to generating the strategy returns and plotting the results. ... The article provides a comprehensive guide on implementing and backtesting a Moving Average Convergence/Divergence (MACD) trading strategy using Python.
🌐
Insider Finance
wire.insiderfinance.io › calculate-macd-in-python-008e1609490f
Calculate MACD in Python. Getting MACD calculations right helps… | by Huzaifa Zahoor | InsiderFinance Wire
January 24, 2025 - Here’s how to implement it in Python with real examples. Want the complete MACD trading guide? Read our detailed analysis at this link. Press enter or click to view image in full size · macd trading view image · MACD (Moving Average Convergence Divergence) combines: Fast EMA (12 periods) Slow EMA (26 periods) Signal line (9-period EMA) def calculate_macd(df, fast=12, slow=26, signal=9): """ Calculate MACD for trading analysis.
🌐
Medium
medium.com › @financial_python › building-a-macd-indicator-in-python-190b2a4c1777
Building a MACD Indicator in Python | by Financial Python | Medium
September 22, 2023 - We’ll use common values for the EMA short-term (12-period) and long-term (26-period) components of MACD and explain why these values are popular choices. Let’s use yfinance to fetch AAPL stock data with a 1-hour timeframe. Import the required libraries and fetch the data: import yfinance as yf # Fetch AAPL stock data with a 1-hour timeframe aapl = yf.Ticker("AAPL") data = aapl.history(period="60d", interval="1h") # Adjust the period as needed · In this step, we’ll calculate the Moving Average Convergence Divergence (MACD) indicator and the Signal Line.
🌐
Medium
medium.com › codex › algorithmic-trading-with-macd-in-python-1c2769a6ad1b
Algorithmic Trading with MACD in Python | by Nikhil Adithyan | CodeX | Medium
September 19, 2023 - It’s none other than Moving Average Convergence/Divergence (MACD). We will first understand what this trading indicator is all about then, we will be implementing and backtesting a trading strategy based on this indicator in python to see how well it’s working in the real world.
🌐
Medium
medium.com › @maneesh1.kumar › macd-analysis-made-easy-with-python-23fd55dab90b
MACD Analysis Made Easy with Python | by Maneesh Kumar | Medium
October 26, 2023 - The Moving Average Convergence ... identification of emerging trends and momentum shifts. Furthermore, Python simplifies the calculation process, further enhancing its accessibility and effectiveness....
🌐
Towards Data Science
towardsdatascience.com › home › latest › cryptocurrency analysis with python – macd
Cryptocurrency Analysis with Python - MACD | Towards Data Science
January 20, 2025 - We are going to apply Moving Average Convergence Divergence (MACD) trading strategy, which is a popular indicator used in technical analysis. MACD calculates two moving averages of varying lengths to identify trend direction and duration. Then, it takes the difference in values between those ...
🌐
Stocksharp
stocksharp.com › store › stocksharp.strategies.0061_macd_divergence.py
MACD Divergence (Python). StockSharp
July 19, 2025 - MACD Divergence looks for disagreement between price action and the MACD indicator. Higher highs in price but lower highs in MACD suggest weakening momentum (bearish divergence), while lower lows in price and higher MACD lows hint at bullish reversal. After detecting divergence, the system ...
🌐
PyPI
pypi.org › project › stockstats
stockstats · PyPI
February 16, 2026 - df['macd'] is the difference between two exponential moving averages.
      » pip install stockstats
    
Published   Feb 16, 2026
Version   0.6.8
🌐
Medium
medium.com › analytics-vidhya › algorithmic-trading-in-python-macd-ca508c0017b
Algorithmic Trading in Python: MACD | by Aidan Wilson | Analytics Vidhya | Medium
April 8, 2021 - The Histogram (Bonus)— While not necessary, a histogram showing the magnitude of the separation between the MACD and signal lines is often also used.
🌐
LinkedIn
linkedin.com › pulse › python-tutorial-macd-moving-average-andrew-hamlet
Investing with Python Tutorial: MACD (Moving Average Convergence/Divergence)
February 8, 2021 - MACD turns two trend-following indicators, moving averages, into a momentum oscillator by subtracting the longer moving average from the shorter moving average. As a result, MACD offers the best of both worlds: trend following and momentum. ... EMA stands for Exponential Moving Average. With that background, let’s use Python to compute MACD.
🌐
EODHD
eodhd.com › home › increasing stock returns by combining williams %r and macd in python
How to Analyze Stock Returns with Williams R MACD Python | EODHD APIs Academy
March 14, 2024 - In this stage, we are poised to put into practice the trading strategy that combines both the Williams %R and Moving Average Convergence/Divergence (MACD) indicators. This strategy will be implemented using Python programming.