MACD

Category: Indicators

The MACD (Moving Average Convergence Divergence) is a trend-following momentum indicator that shows the relationship between two moving averages of a security’s price. The MACD is calculated by subtracting the 26-period Exponential Moving Average (EMA) from the 12-period EMA. The result of this calculation is the MACD line. A nine-day EMA of the MACD called the “signal line,” is then plotted on top of the MACD line, which can function as a trigger for buy and sell signals.

Syntax:

MACD[S, L, Si](price)
  • S (short period): Number of periods for the shorter EMA (typically 12).
  • L (long period): Number of periods for the longer EMA (typically 26).
  • Si (signal period): Number of periods for the signal line’s EMA (typically 9).
  • price: The price series to be used (commonly the closing price).

Example:

i1 = MACD[12,26,9](close)
FOR i = 20 DOWNTO 0 DO
    IF(close[i] < close[i+1] AND i1 > i1[1]) THEN
        result = 100
    ELSE
        result = 0
    ENDIF
NEXT
RETURN result

This example calculates the MACD for the closing price with typical parameters (12, 26, 9). It then checks for a condition over the last 21 bars where the closing price is increasing and the MACD value is greater than its previous value. If both conditions are met, it assigns a result of 100; otherwise, it assigns a result of 0.

Additional Information:

  • The MACD histogram is the graphical representation of the difference between the MACD and its signal line. Positive values indicate upward momentum, while negative values indicate downward momentum.
  • The MACD is particularly useful in identifying trend direction and reversals through divergences and crossovers.
  • A bullish divergence occurs when the price records a lower low but the MACD forms a higher low, suggesting a potential reversal in upward direction.
  • A bearish divergence occurs when the price records a higher high but the MACD forms a lower high, suggesting a potential reversal in downward direction.

The MACD is a versatile tool in technical analysis, providing insights into both the momentum and direction of market prices.

Related Instructions:

  • DivergenceMACD indicators
  • MACDLine indicators
  • MACDsignal indicators
  • Logo Logo
    Loading...