DINEXSPACEXAUUSD SpecialistEAs available to rentCustom EA: Strategy → Code → BacktestView rentable EA bots
// MACD.MQ5

What is the MACD indicator?

MACDMomentum

Uses the distance between two moving averages as a measure of momentum, with a histogram for the rate of change.

What is Moving Average Convergence Divergence?

The difference between two EMAs (fast and slow) plus a signal line, measuring momentum and trend direction.

MACD — MACD(12,26,9) 5.51 / signal 2.58 — SIMULATEDDINEXSPACE / MomentumMACD(12,26,9) 5.51 / signal 2.58XAUUSD · 1H / SIMULATEDRESSUP2,332.62,360.82,445.42,430.2▲ BUYCandle 68: BUY▼ SELLCandle 87: SELL▲ BUYCandle 105: BUYVOL*0MACD / SignalCANDLE 1CANDLE 29CANDLE 57CANDLE 85CANDLE 112MA · EMA 14 ━━━━ / VOL* · ILLUSTRATIVE CANDLE RANGEEMA 14Illustrative data — not real market data, not a trading signalMACD — MACD(12,26,9) 5.51 / signal 2.58 — SIMULATEDMACD 12/26/9XAUUSD · 1H / SIMULATEDRESSUP2,332.62,430.2▲ BUYCandle 105: BUYVOL*0MACD / SignalMACD — MACD(12,26,9) 5.51 / signal 2.58 — SIMULATEDMACD 12/26/9XAUUSD · 1H / SIMULATEDRESSUP2,332.62,430.2▲ BUYCandle 105: BUYVOL*0MACD / SignalMACD — MACD(12,26,9) 5.51 / signal 2.58 — SIMULATEDMACD 12/26/9XAUUSD · 1H / SIMULATEDRESSUP2,332.62,430.2▲ BUYCandle 105: BUYVOL*0MACD / SignalEMA 14Illustrative data — not real market data, not a trading signal

Illustrative signals of the rule on simulated data — not a trading recommendation.

Rule: MACD(12,26) crosses above Signal(9): buy; crosses below: sell. Entry = close of the signal candle; SL = entry ∓ 1.5 × ATR(14); TP1/TP2/TP3 = 1R/2R/3R.

Use this indicator to create a Custom EA brief →
// WHY_USE_IT

Where this indicator is strong

Three reasons Moving Average Convergence Divergence is still used after decades.

Three layers of information

The MACD line, the signal line and the histogram — each layer answers a different question.

Shows momentum fading

The bars shrink before price reverses, earlier than the crossover signal.

No fixed scale needed

Because it is measured in price units, it reflects the real range of the pair you are viewing.

// READING_SIGNALS

How to read Moving Average Convergence Divergence signals

How MACD produces its number, and what each shape on the chart means.

Formula and how it works

The MACD line = fast EMA (12) minus slow EMA (26) of the close. The Signal line is the EMA (9) of the MACD line itself. Histogram = MACD − Signal, showing the strength or weakness of momentum; MACD crossing above Signal is a bullish signal.

How to use it in an EA

Enter when MACD crosses Signal; use a shrinking histogram as a warning that momentum is fading; MACD–price divergence signals a possible reversal.

Fits when

The market has clear trending swings, enough for the gap between the two averages to widen.

Struggles when

Sideways phases. MACD wraps around the zero line and crossovers appear constantly without leading to any move.

MACD crosses above the signal lineMomentum turns upward; a cross below is the opposite.
The histogram shrinks toward 0Momentum is weakening, even if price may still be moving on.
MACD crosses the zero lineThe two underlying averages have just swapped order — the base trend has changed direction.
Price makes a lower low, MACD does notBullish divergence, warning that selling pressure is running out.
Common mistakes

Entering on every crossover. MACD is a lagging indicator, so its signals need a trend filter in front of them.

// PARAMETERS

Recommended MT5 parameters for Moving Average Convergence Divergence

Default values of the sample file; test them for your market and timeframe.

ParameterDescription
InpFastFast EMA period (default 12).
InpSlowSlow EMA period (default 26).
InpSignalEMA period of the signal line (default 9).
// INSTALL

Put the indicator into MetaTrader 5

Four steps, no software needed besides MT5.

01Download the .mq5 file

Click the download button above; the file saves to your computer under the indicator's name.

02Open the data folder

In MetaTrader 5 choose File → Open Data Folder, then go to MQL5/Indicators.

03Compile

Open the file in MetaEditor and click Compile. No errors means the indicator is ready.

04Drag it onto the chart

Go back to MT5, refresh the Navigator and drag the indicator onto the price chart.

📄 macd.mq5

DinexSpace wrote this file from the indicator's public formula, not from any commercial source. You are free to edit and reuse it.

// THE_DIFFERENCE

How it differs from MetaTrader 5's built-in indicator

The short answer: the formula is not different. What differs is what you can do with it.

Moving Average Convergence Divergence here gives exactly the same number as MetaTrader 5's built-in version — on purpose. The four points below are what differs, and all four can be read from the very macd.mq5 you download.

Calls a built-in indicator
No — the calculation sits in OnCalculate and can be copied straight into an EA
External libraries
Not a single #import declaration
Code length
58 lines · 3 input parameters
How it draws
A separate window below the price chart · calculated incrementally, does not redraw the past

Why this library promises no secret formula — read the full explanation on the library page.

// COMBINATIONS

Which indicators to pair Moving Average Convergence Divergence with, and what you gain

Each indicator only answers one question. Pairing well means covering the right weakness, not stacking more.

Moving Average Convergence DivergenceMoving Average
What you gain
Filters the base trend. A long MA decides whether you may only buy or only sell, MACD handles timing within that direction.
Note
MACD is already built from two moving averages, so the MA here must use a much longer period to add any information.
See Moving Average
Moving Average Convergence DivergenceRelative Strength Index
What you gain
Double divergence. When both MACD and RSI diverge from price, the warning that momentum is fading comes from two different measures.
Note
Both are lagging indicators. Double divergence makes the signal firmer but also later.
See Relative Strength Index
Moving Average Convergence DivergenceAverage Directional Index
What you gain
Drops meaningless crossovers. MACD produces many crosses when the market is choppy; ADX removes most of them.
Note
The trade-off is missing the start of a new trend, because ADX needs time to rise.
See Average Directional Index
// FAQ

Frequently asked questions about Moving Average Convergence Divergence

How do MACD and RSI differ?

RSI measures the strength of a move and maps it to a fixed 0-100 scale. MACD measures the distance between two moving averages, in price units, so it has no ceiling. RSI suits sideways markets, MACD suits markets with trending swings.

What is the MACD histogram for?

Each bar is the difference between the MACD line and the signal line. Shrinking bars mean the two lines are converging, so momentum is weakening — this comes before the actual crossover, so it is an early warning.

Does Moving Average Convergence Divergence on this page use real or simulated data?

The chart on this page uses a deterministic simulated candle series; it is not market prices or trading results.

// SAME_GROUP

Other momentum indicators

Indicators in the same momentum group, often used instead of or alongside Moving Average Convergence Divergence.

Turn Moving Average Convergence Divergence into an automated EA

An indicator draws signals, but when to enter, where to stop out and how much to risk are still your set of rules. Send those rules and DinexSpace builds them into an EA.

Use this indicator to create a Custom EA brief