OPEN-SOURCE SCRIPT

MACD including 6-period Forecast and Divergences

█ OVERVIEW

This is my personal interpretation of the classic MACD Indicator. I am using the MACD as part of my analysis, and often I was wondering when I can expect the next signal (e.g. a Histogram cross). As I had come across some EMA forecast logics on tradingview, my goal was to use the EMA forecast calculation as basis to come to a complete MACD forecast. Here is the result.

Starting point is the classic MACD which is then plotted with MACD-Line, Signal Line and Histogram. In addition to the classic MACD, a 6 period Forecast for MACD, Signal and Histogram is available and divergences can be displayed on either the Histogram or the MACD Line.

Important:
As I am considering the closing price of the current candle as the basis for the calculation, the forecast values will REPAINT. But in my opinion this is fine as this indicator will not provide direct trading signals, but more an outlook into a potential future.


█ CALCULATION LOGIC

Below some details regarding the additional functionalities:

MACD Forecast:

The MACD Forecast is mainly based on a combination of EMA Forecasts. The inspiration for this basic forecast calculation is taken from the below tradingview members:
--> EMA Forecast input taken from "Triple MA Forecast" by yatrader2
--> Forecast Bias input taken from "Fancy Bollinger Bands" by BigBitsIO

When showing the forecast, the following options are available:
- Forecast Type: Determines if the Forecast is assuming a Flat price (last values of the MA calculation are replaced by current value) or if a Linear Regression is taken
- Number of candles taken for Linear Regression Calculation
- Bias of Forecast (Based on the recent Average True Range, the forecast values are either more bullish or more bearish calculated. "Neutral" turns off this function)
- Number of ATR Periods used to calculate Bias adjustment value
- Possibility to weight the Bias via a Multiplier - Default value is 1

Based on the above inputs, the forecasted values for MACD, Signal Line and Histogram are calculated and plotted for the next 6 periods.


Divergence Detection:

Based on the default tradingview divergence script with some adjustments:
- User can select to use either Histogram or MACD Line as basis for Divergence detection (Histogram by default)
- User can select if Divergence detection should be based on the candles including Wicks or only the Candle Bodies (Wicks by default)


█ DISCLAIMER

This is an experimental indicator and I do not know if my theory works in real life. So treat this not as financial advise, but purely for entertainment and educational purposes.
I publish this code open so that everyone can re-use it or hopefully even improve it.


Let me know if you have any ideas for improvement and if it is within my coding capabilities (which to be honest are quite limited), I will try to accomodate it.

Have fun.
Centered OscillatorsMoving Average Convergence / Divergence (MACD)

Script open-source

Dans le plus pur esprit TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par nos Règles. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Vous voulez utiliser ce script sur un graphique ?


Aussi sur:

Clause de non-responsabilité