Moving Average Convergence Divergence
systemic:core-macdIndicatorsfunction1 crInputs
| Name | Type | Description |
|---|---|---|
| Short Window / Short EMA | integer | The period length for the **fast EMA** in the MACD calculation. |
| Long Window / Long EMA | integer | The period length for the **slow EMA** in the MACD calculation. |
| Signal Window / Signal Line | integer | The period length for the **Signal Line EMA**—an EMA applied to the MACD Line itself. |
| Price | floatarray | The time series of price values used as input for the MACD calculation. |
Outputs
| Name | Type | Description |
|---|---|---|
| MACD | floatarray | The **MACD Line**—the core momentum indicator representing the difference between fast and slow exponential moving averages. |
The MACD (Moving Average Convergence Divergence) is one of the most widely recognized momentum indicators in technical analysis. Created by Gerald Appel in the late 1970s, it remains a cornerstone of trading systems because it elegantly combines trend-following and momentum analysis into a single measure.
What this module outputs: The MACD Line—the difference between a fast and slow EMA. To build a complete MACD system with Signal Line and Histogram, combine this module with additional EMA and subtraction modules.
The Intuition Behind MACD
When a fast moving average is above a slow moving average, short-term prices are higher than the longer-term average—bullish momentum. When it's below, short-term prices are lagging—bearish momentum.
MACD quantifies this relationship by measuring the distance between the two averages.
flowchart LR
subgraph Price["Price Action"]
P["Closing Prices"]
end
subgraph EMAs["Exponential Moving Averages"]
F["Fast EMA (12)"]
S["Slow EMA (26)"]
end
subgraph Output["MACD Line"]
M["Fast − Slow"]
end
P --> F
P --> S
F --> M
S --> M
Interpreting MACD Values
| MACD Value | Meaning |
|---|---|
| Positive (+) | Fast EMA > Slow EMA → Bullish momentum |
| Negative (−) | Fast EMA < Slow EMA → Bearish momentum |
| Rising | Momentum is strengthening |
| Falling | Momentum is weakening |
| Crossing Zero | Trend direction may be reversing |
The Zero Line
The zero line is the equilibrium point where fast and slow EMAs are equal. Crosses above or below zero often signal significant trend changes:
flowchart TD
subgraph Above["MACD > 0"]
A1["Fast EMA above Slow EMA"]
A2["Uptrend momentum"]
end
subgraph Cross["MACD = 0"]
C1["EMAs are equal"]
C2["Potential trend change"]
end
subgraph Below["MACD < 0"]
B1["Fast EMA below Slow EMA"]
B2["Downtrend momentum"]
end
Above --> Cross --> Below
Real-World Example: SPY EMAs
Using recent SPY (S&P 500 ETF) data (December 2024):
| Date | EMA-12 |
|---|---|
| 2024-12-29 | $683.92 |
| 2024-12-26 | $683.21 |
| 2024-12-24 | $681.92 |
| 2024-12-23 | $680.38 |
| 2024-12-22 | $679.00 |
When the 12-period EMA is rising while staying above the 26-period EMA, the MACD Line is positive and increasing—confirming bullish momentum.
Configuration Parameters
| Parameter | Default | Description |
|---|---|---|
| Short Window | 12 | Fast EMA period |
| Long Window | 26 | Slow EMA period |
| Signal Window | 9 | Smoothing for the Signal Line (used downstream) |
Why 12-26-9?
These defaults were established by Gerald Appel for daily stock charts:
- 12 days ≈ Two trading weeks (short-term trend)
- 26 days ≈ One trading month (medium-term trend)
- 9 days ≈ Signal Line smoothing
Alternative Configurations
| Market Condition | Short | Long | Rationale |
|---|---|---|---|
| High Volatility | 8 | 17 | More responsive to rapid changes |
| Low Volatility | 19 | 39 | Filters out noise |
| Crypto/Forex (24/7) | 12 | 26 | Standard works well |
| Weekly Charts | 12 | 26 | Same proportions, larger timeframe |
Building a Complete MACD System
This module outputs only the MACD Line. To build a full MACD trading system, combine it with other modules:
flowchart TD
subgraph Step1["1. MACD Module"]
M["MACD Line = EMA₁₂ − EMA₂₆"]
end
subgraph Step2["2. Add EMA Module"]
E["Signal Line = EMA₉ of MACD"]
end
subgraph Step3["3. Add SUB Module"]
H["Histogram = MACD − Signal"]
end
subgraph Signals["Trading Signals"]
S1["Crossovers"]
S2["Zero-line crosses"]
S3["Divergence"]
end
Step1 --> Step2 --> Step3 --> Signals
Complete MACD Components
| Component | Formula | What It Shows |
|---|---|---|
| MACD Line | EMA₁₂ − EMA₂₆ | Momentum direction |
| Signal Line | EMA₉ of MACD | Smoothed momentum |
| Histogram | MACD − Signal | Momentum acceleration |
Trading Strategies
Strategy 1: Zero-Line Crossover
The simplest and most reliable MACD signal—trade when MACD crosses zero.
| Signal | Condition | Interpretation |
|---|---|---|
| Bullish | MACD crosses above 0 | Short-term trend now above long-term |
| Bearish | MACD crosses below 0 | Short-term trend now below long-term |
Strength: These signals are less frequent but more reliable than Signal Line crossovers.
Strategy 2: MACD Direction
Monitor whether MACD is rising or falling, regardless of its absolute value.
| MACD Behavior | Interpretation |
|---|---|
| Rising from deeply negative | Bearish momentum slowing, potential reversal |
| Falling from positive | Bullish momentum weakening |
| Accelerating upward | Strong bullish pressure |
Strategy 3: Divergence Detection
Compare MACD direction to price direction—divergence often precedes reversals.
| Type | Price Action | MACD Action | Meaning |
|---|---|---|---|
| Bullish Divergence | Lower lows | Higher lows | Selling exhaustion |
| Bearish Divergence | Higher highs | Lower highs | Buying exhaustion |
MACD vs. Other Indicators
| Indicator | Measures | MACD Advantage |
|---|---|---|
| RSI | Overbought/Oversold | MACD shows trend direction |
| Stochastic | Price position in range | MACD works in trends, not just ranges |
| ADX | Trend strength only | MACD shows direction + momentum |
| Simple MA Crossover | Trend only | MACD is smoother (uses EMAs) |
Strengths
| Aspect | Benefit |
|---|---|
| Dual nature | Captures both trend and momentum |
| Visual clarity | Easy to interpret rising/falling patterns |
| Versatility | Works across timeframes and asset classes |
| Well-established | Decades of trader experience and research |
Limitations
| Aspect | Challenge |
|---|---|
| Lagging | Based on moving averages—inherently delayed |
| False signals | Whipsaws common in ranging/choppy markets |
| Not bounded | Unlike RSI, no overbought/oversold levels |
| Requires confirmation | Best used with other indicators |
Combining MACD with Other Modules
| Combination | Purpose |
|---|---|
| MACD + EMA | Create Signal Line for crossover signals |
| MACD + RSI | Confirm: MACD bullish + RSI not overbought = stronger signal |
| MACD + ATR | Use ATR for position sizing based on volatility |
| MACD + Volume | Volume spike + MACD cross = higher confidence |
| MACD + Bollinger Bands | Volatility squeeze + MACD cross = breakout signal |
Historical Context
Gerald Appel introduced MACD in his 1979 book "The Moving Average Convergence Divergence Trading Method". Originally designed for stocks, it has proven remarkably adaptable across asset classes—forex, crypto, commodities, and indices all respond well to MACD analysis.
The indicator's longevity (over 45 years) speaks to its fundamental soundness: it captures the universal market dynamic of short-term momentum relative to longer-term trends.
Data Alignment in Systemic
The MACD module accepts a single price series input. Since all window parameters (Short, Long, Signal) are constants, alignment primarily concerns the price_data input.
Single-Input Behavior
The price_data input typically comes directly from an asset data source. If connected to a module that outputs a processed series:
- Systemic ensures the data reaches MACD as a continuous numeric sequence
- No multi-input alignment is required since only one price series is used
Parameter Constants
All three window parameters (Short, Long, Signal) must be constants:
- They cannot be connected to time-varying module outputs
- This ensures consistent EMA calculations across the entire series
Data Length Requirements
MACD requires sufficient data to compute the longest EMA:
With default settings (12, 26, 9), you need at least 26 data points.
Missing Data
Both EMAs run over observed bars only and are reindexed back to the full input grid:
- Closed-market gaps (e.g. weekends) stay gaps, and bridge. A missing input slot produces
Nonein the output — never a carried-forward (stale) MACD value, never a zero-line sentinel. The EMA decay across a gap treats the next observed bar (e.g. Monday) as adjacent to the last observed bar (Friday), not as many calendar days removed — the correct bar-adjacent decay. - Warm-up is
None, never0.0. The firstlong_window − 1observed bars are honestly undetermined — retired the prior fabricated0.0warm-up, which traders could misread as a zero-line crossover signal. - Live mode. MACD returns exactly one value for a live request: the most recent slot's MACD,
or
Noneif that slot itself is a closed-market gap or still inside the observed-bar warm-up.
Indicator Profile
The following chart compares MACD's utility across stocks and cryptocurrency markets:
quadrantChart
title MACD Indicator Profile
x-axis Low Popularity --> High Popularity
y-axis Low Reliability --> High Reliability
quadrant-1 High potential
quadrant-2 Established leaders
quadrant-3 Niche tools
quadrant-4 Popular but risky
MACD - Stocks: [0.90, 0.75]
MACD - Crypto: [0.85, 0.65]
Dimension Ratings
| Dimension | Stocks | Crypto | Notes |
|---|---|---|---|
| Popularity | 9.0/10 | 8.5/10 | One of the most widely used indicators globally. Standard on every trading platform. |
| Reliability | 7.5/10 | 6.5/10 | Reliable in trending markets. Crypto's higher volatility increases false signals. |
| Complexity | 4.0/10 | 4.0/10 | Conceptually simple (EMA difference). Most traders can interpret it quickly. |
| Versatility | 8.5/10 | 8.0/10 | Works across all timeframes and asset classes. Default settings widely applicable. |
| Recent Interest | 7.5/10 | 7.0/10 | Steady classic indicator. Continues to appear in research and trading education. |