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 linemacdsignal: Signal linemacdhist: 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 LineWhere:
- FastMA is the fast moving average
- SlowMA is the slow moving average
- EMA is Exponential Moving Average
Usage Scenarios
- Trend Identification
- Momentum Analysis
- Trading Signal Generation
- Divergence Analysis
Usage Recommendations
- MACD line crossing above signal line is a buy signal
- MACD line crossing below signal line is a sell signal
- Watch for histogram changes
- Pay attention to divergence patterns