MACD Indicator: Signal Line, Histogram and Trading Bot Rules
How MACD is built from two EMAs, what the signal line and histogram show, which MACD signals are worth automating, and why MACD crossovers alone rarely make a robust bot.
MACD (Moving Average Convergence/Divergence) turns the relationship between two moving averages into an oscillator. Developed by Gerald Appel, it is one of the most widely used momentum indicators. It is simple to automate - which is exactly why many first trading bots are MACD crossover bots, and why most of them disappoint.
How MACD is built
With the classic settings 12, 26, 9:
- MACD line = EMA(12) − EMA(26).
- Signal line = EMA(9) of the MACD line.
- Histogram = MACD line − signal line.
MACD is positive when the short EMA is above the long EMA (upward momentum) and negative when it is below.
What each part tells you
| Component | Meaning |
|---|---|
| MACD above zero | Short-term average above long-term: upward bias |
| MACD crossing zero | The two EMAs crossing: trend change signal |
| MACD crossing signal line | Momentum accelerating or decelerating |
| Histogram growing | Momentum strengthening |
| Histogram shrinking | Momentum fading, often before a crossover |
| Divergence | Price new high, MACD lower high (or reverse) |
Because MACD is in price units, its size depends on the instrument and volatility. A value of 0.0005 on EURUSD and 5.0 on gold may mean the same thing.
Signals worth automating
1. Zero-line as a trend filter
Allow longs only when MACD > 0 and shorts only when MACD < 0. This is effectively an EMA crossover filter and works as a simple regime gate for other entries.
2. Signal-line cross in the direction of the trend
Enter long when MACD crosses above its signal line while MACD is above zero (or price is above a long moving average). This takes pullback-and-resume entries in an existing trend.
3. Histogram turning points
Enter when the histogram stops falling and turns up during an uptrend - an early pullback-end signal. Earlier than a crossover, but noisier.
4. Normalised MACD thresholds
Divide MACD by ATR to get comparable values across markets, then require a minimum strength before trading.
Why plain crossover bots fail
- Lag. Both lines are averages of averages; signals arrive after much of the move.
- Whipsaws. In ranges, MACD crosses its signal line constantly; each cross costs spread and a small loss.
- Optimisation trap. Three periods to tune invite curve fitting. The classic 12/26/9 is as good a starting point as any.
A more robust design
Gold H1 trend-continuation bot:
- Trend filter: price above EMA(200) and MACD(12,26,9) above zero.
- Entry: MACD crosses above signal line after the histogram has been negative (a pullback).
- Stop: below the pullback low or 2 × ATR.
- Exit: trailing stop or MACD crossing below zero.
- Regime gate: skip if ADX(14) < 18.
Each component has a clear job: MACD defines trend and pullback, ATR defines risk, ADX avoids flat markets.
Pitfalls
- Using open-bar values (signals that appear and vanish within a bar).
- Comparing raw MACD thresholds across instruments.
- Treating divergences as automatic reversal signals.
- Ignoring that MACD is just a moving-average spread - combining it with another EMA crossover adds little.
Key takeaways
- MACD = fast EMA − slow EMA, with a signal line and histogram for acceleration.
- Use it as a trend filter or for pullback entries within trends, not as a stand-alone crossover system.
- Normalise by ATR when comparing markets.
- Keep the classic settings unless robust tests justify changes.
Related: moving averages and momentum trading.
FAQ
What do the MACD settings 12, 26, 9 mean?
The MACD line is the 12-period EMA minus the 26-period EMA. The signal line is a 9-period EMA of the MACD line. The histogram is the difference between the two.
Is a MACD crossover a good entry signal?
On its own it is a lagging, frequent signal that whipsaws in ranges. It works better as a trend filter or combined with a regime filter and price structure.
Can MACD be compared across markets?
Not directly, because it is measured in price units. Normalise it, for example by dividing by ATR or price, if you want comparable thresholds.
Sources and further reading
- StockCharts ChartSchool: MACD (Moving Average Convergence/Divergence Oscillator) - chartschool.stockcharts.com
- StockCharts ChartSchool: Moving Averages - Simple and Exponential - chartschool.stockcharts.com