Moving Average Convergence Divergence (MACD)
MACD
MACD is an unbounded momentum oscillator built from two moving averages. It tracks the gap between a fast and a slow EMA to show when momentum is accelerating, stalling, or turning — and its signal-line and zero-line crossovers make it one of the most direct indicators to turn into a no-code EA.
- Default settings
- 12 / 26 / 9
- Signal period
- 9
- Centre
- Zero line
示意性 — 合成数据,非实时报价。
What MACD tells you
MACD turns two moving averages into a single momentum reading. It subtracts a slow EMA from a fast one, so the result grows when a move is accelerating and shrinks as it fades — and a second, smoothed line marks the moment that momentum changes hands.
- Above zero: the fast EMA leads — bullish momentum bias
- Below zero: the slow EMA leads — bearish momentum bias
- MT5 draws MAIN_LINE as the histogram — the bars are the MACD line, not MACD minus signal
- 1 Fast EMA minus slow EMA → MAIN_LINE
- 2 MAIN_LINE smoothed → SIGNAL_LINE
- 3 MT5 draws MAIN as bars, SIGNAL as a line
显示公式与计算详情
MACD is derived from moving averages of price — the 12, 26, and 9 period settings by default. In MetaTrader 5 the indicator publishes two buffers:
- Compute the fast EMA (12 periods) and the slow EMA (26 periods) of the applied price.
- Subtract the slow EMA from the fast EMA. This difference is MAIN_LINE (buffer 0):
MAIN = EMA(12) − EMA(26). The MT5 terminal draws this buffer as the histogram. - Average MAIN_LINE over the signal period to get SIGNAL_LINE (buffer 1):
SIGNAL = MA(MAIN, 9). MT5’s standard MACD uses a simple moving average here; the classic construction uses a 9-period EMA. The terminal draws this buffer as the line over the histogram.
There is no third buffer. MAIN − SIGNAL — the quantity most other charting packages draw as the MACD histogram — is a separate MetaTrader indicator, the Moving Average of Oscillator (OsMA), called with iOsMA. Keeping the two names apart matters in practice: “the histogram flipped sign” means something different on an MT5 chart (MAIN crossed zero) than it does elsewhere (MAIN crossed SIGNAL).
Because it is built from moving averages rather than a bounded ratio, MACD is unbounded. Its values scale with the instrument’s price and volatility, so a reading of 0.0020 on EUR/USD is not comparable to 0.20 on an index. What carries meaning is MAIN_LINE’s position relative to zero and to SIGNAL_LINE, not the absolute number.
In MQL5 the call is iMACD(symbol, period, fast_ema_period, slow_ema_period, signal_period, applied_price). applied_price is a full ENUM_APPLIED_PRICE argument, so the EMAs can be built from Open, High, Low, Median, Typical or Weighted price as well as Close. Gerald Appel developed the original MACD in the late 1970s.
信号
MACD 提供的可回测信号 — 及每个信号适合的市场状态。
Zero-Line Crossover
Builder 可实现Divergence
高级逻辑OsMA Momentum
Builder 可实现MT5 实现
MetaTrader 5 实际计算和绘制的内容——本页每条规则的依据。
缓冲区
| 索引 | 缓冲区 | MT5 中的绘制方式 | 存放内容 |
|---|---|---|---|
| 0 | MAIN_LINE | Histogram | Fast EMA minus slow EMA. This is the buffer the MT5 terminal draws as the histogram — it is the MACD line itself, not a difference from the signal. |
| 1 | SIGNAL_LINE | Line | MAIN_LINE smoothed over the signal period, drawn as the line over the histogram. MT5's standard MACD smooths it with a simple moving average. |
平台说明
最佳适用场景 / 谨慎使用
没有任何指标具有普适优势。以下是 MACD 发挥作用的场景 — 以及可能误导的场景。
最佳适用场景
- Trending markets
- Clear momentum shifts
- With a trend or volatility filter
- On higher timeframes
谨慎使用
- Tight, directionless ranges
- MACD alone as an entry
- Fast settings on low timeframes
- Optimised settings without validation
构建 MACD 策略
将信号接入进场和出场规则,然后导出可编译的 MT5 EA — 无需编写代码。
- MACD MAIN (12/26/9)
- MACD SIGNAL (12/26/9)
- MAIN crosses above SIGNAL → Open Buy · SL 40 / TP 80
- MAIN crosses below SIGNAL → Open Sell
将 MACD 与其他指标组合
单一指标很少独立有效。这些组合弥补了 MACD 的盲点。
MACD + OsMA
- OsMA above zero
- OsMA rising against its own value 3 bars back
- Buy
There is no template that places MACD and OsMA in one flow, and there should not be: OsMA is MAIN − SIGNAL, so both together would state the same crossover twice. The OsMA Re-acceleration + Zero Line template shows the OsMA form on its own.
打开 Builder →MACD + RSI
- MAIN crosses above SIGNAL
- RSI > 50
- Buy
No template pairs MACD with RSI. Start from MACD Signal and add an RSI node, a Compare at 50 and an And gate ahead of the Buy action.
打开 Builder →MACD + ADX
- ADX > 25
- MAIN crosses above SIGNAL
- Buy
No template pairs MACD with ADX. Start from MACD Signal and add an ADX node with a Compare at 25 — the ADX Trend template shows that filter wired up.
打开 Builder →MACD + Moving Average
- Price > 200 MA
- MAIN crosses above SIGNAL
- Buy
No template pairs MACD with a moving average. Start from MACD Signal and add an MA node plus a Price node into a Compare, gated with And.
打开 Builder →参数
在您自己的货币对和时间框架上验证的起始值 — 非保证设置。
| 参数 | 默认值 | 建议测试范围 | 功能说明 |
|---|---|---|---|
| Fast EMA | 12 | 5–20 | The faster moving average. Shorter reacts sooner and fires more crossovers; longer is calmer and slower to turn. |
| Slow EMA | 26 | 20–40 | The slower moving average. The gap between fast and slow is MAIN_LINE itself — widen it for fewer, larger swings. |
| Signal period | 9 | 5–15 | Averaging period applied to MAIN_LINE to produce SIGNAL_LINE. Lower is twitchier; higher lags more but whipsaws less. MT5's standard MACD smooths with a simple moving average, so this is a period, not an EMA length. |
| Applied price | Close | Close / Open / High / Low / Median / Typical / Weighted | Price series the two EMAs are built from. Close is the MT5 default and the standard choice; iMACD accepts any ENUM_APPLIED_PRICE value, so this is selectable, not fixed. |
初始预设
市场示例
MACD 有效的场景、失效的场景,以及过滤器如何改变结果。
Crossover that caught the trend
As a market began to trend, MAIN_LINE crossed up through SIGNAL_LINE near the zero line and the move followed through — the textbook momentum-entry case.
Whipsaw in a flat market
In a tight range MAIN_LINE hugs SIGNAL_LINE and crosses back and forth. Trading every cross here churns costs with no move to ride.
Filtered by trend strength
Add an ADX or moving-average filter and the same cluster of crossovers is ignored while the market goes nowhere — the filter is what separates a real signal from range noise.
FAQ
- What are the best MACD settings for an EA?
- 12 / 26 / 9 is Gerald Appel's default and the right starting point. Faster settings (for example 8 / 17 / 9) react sooner but whipsaw more; slower ones give fewer, higher-conviction signals. Treat any setting as a baseline to re-validate on your own pair and timeframe in a backtest, not as portable truth.
- Is the signal-line cross or the zero-line cross better?
- They answer different questions. The signal-line cross times momentum changing hands and fires earlier; the zero-line cross confirms the momentum bias has actually flipped and fires later with fewer false starts. A common EA design uses the zero line as a filter and the signal cross as the trigger.
- Why does MACD whipsaw so much in ranges?
- Because it is built from moving averages. In a flat market the fast and slow EMAs sit almost on top of each other, so MAIN_LINE crosses SIGNAL_LINE repeatedly with no trend to profit from. Pair it with a trend-strength filter such as ADX, or a higher-timeframe moving average, before trading the crosses.
- Where is the MACD histogram in MT5?
- The histogram you see on an MT5 chart is MAIN_LINE — the fast EMA minus the slow EMA — drawn as bars, with SIGNAL_LINE as the line over it. iMACD has no third buffer. The MACD-minus-signal histogram used by most other charting packages exists in MT5 as a separate indicator, OsMA (Moving Average of Oscillator), reached with iOsMA. So bars shrinking toward zero on an MT5 MACD means momentum itself is fading, not that the two lines are converging.
- Is the MT5 signal line a 9-period EMA?
- No. MT5's standard MACD averages MAIN_LINE with a simple moving average over the signal period, while the classic construction uses a 9-period EMA. That is why this page says signal period rather than signal EMA. The two shapes are similar, but crossovers can land a bar apart — enough to matter when comparing an MT5 backtest with a chart drawn in another package.
- How should I validate MACD settings before going live?
- Backtest on quality tick data first, then run the EA on a demo account before risking money. When optimising, hold back data the search never saw and prefer settings that stay profitable across periods over the single in-sample peak — chasing that peak is overfitting the noise. No default or preset here is a performance promise; every value is a starting point to re-validate on your own pair and broker.