DivergenceMACD

Category: Indicators

The DivergenceMACD function in ProBuilder language is designed to identify and return signals of potential divergences between the price of an asset and its Moving Average Convergence Divergence (MACD) indicator. Divergences can signal a possible reversal in the current price trend, making this function useful for technical analysis in trading strategies.

Syntax:

DivergenceMACD[FastPeriod, SlowPeriod, SignalPeriod, Bars](price)
  • FastPeriod: Number of periods for the fast moving average in the MACD calculation. Default is 12.
  • SlowPeriod: Number of periods for the slow moving average in the MACD calculation. Default is 26.
  • SignalPeriod: Number of periods for the signal line moving average in the MACD. Default is 9.
  • Bars: Number of bars to analyze for detecting potential divergences. Default is 20.
  • price: The price data (typically close price) to be used in the calculation.

Calculation:

The DivergenceMACD function detects two types of divergences:

  • Bullish Divergence: Occurs when the price records lower lows while the MACD indicator begins to rise. This suggests a weakening of the downward trend and a potential upward reversal.
  • Bearish Divergence: Occurs when the price records higher highs while the MACD indicator begins to fall. This suggests a weakening of the upward trend and a potential downward reversal.

Interpretation:

The function returns:

  • +1 for a bullish divergence (indicating a potential upward move).
  • -1 for a bearish divergence (indicating a potential downward move).
  • 0 when no divergence is detected.

Example:

i = DivergenceMACD[12,26,9,20](close)
return i style(histogram)

This example sets up the DivergenceMACD function with default MACD settings and checks for divergences over the last 20 bars using the closing price. The result is returned as a histogram where positive values (green) indicate bullish divergences and negative values (red) indicate bearish divergences.

Tip: When analyzing divergences, ensure that the MACD and DivergenceMACD parameters are consistent to maintain accuracy in your analysis.

Related Instructions:

  • DivergenceCCI indicators
  • DivergenceRSI indicators
  • Logo Logo
    Loading...