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.
สัญญาณ
สัญญาณที่ backtest ได้ของ MACD — และสภาวะตลาดที่เหมาะสมกับแต่ละสัญญาณ
Zero-Line Crossover
พร้อมใช้ใน BuilderDivergence
ตรรกะขั้นสูง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
เชื่อมสัญญาณเข้ากับกฎการเปิดและปิดออเดอร์ จากนั้นส่งออก EA MT5 ที่คอมไพล์ได้ — ไม่ต้องเขียนโค้ด
- 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.
บทความที่เกี่ยวข้อง
Glossary