Skip to content

Indicator Description

MACD (Moving Average Convergence Divergence) is a trend-following momentum indicator that displays price momentum changes by calculating the difference between two moving averages of different periods.

Function Information

  • Function Name: MACD
  • Input Parameters:
    • Close: Closing price
  • Parameter Settings:
    • fastperiod: Fast period (default: 12)
    • slowperiod: Slow period (default: 26)
    • signalperiod: Signal period (default: 9)
  • Output:
    • macd: MACD line
    • macdsignal: Signal line
    • macdhist: MACD histogram

Calculation Principle

MACD is calculated using the following formula:

MACD Line = FastMA - SlowMA
Signal Line = EMA(MACD Line, signalperiod)
MACD Histogram = MACD Line - Signal Line

Where:

  • FastMA is the fast moving average
  • SlowMA is the slow moving average
  • EMA is Exponential Moving Average

Usage Scenarios

  1. Trend Identification
  2. Momentum Analysis
  3. Trading Signal Generation
  4. Divergence Analysis

Usage Recommendations

  1. MACD line crossing above signal line is a buy signal
  2. MACD line crossing below signal line is a sell signal
  3. Watch for histogram changes
  4. Pay attention to divergence patterns