How it works
MACD converts the relationship between two exponential moving averages into a single oscillating line. When the fast average pulls away from the slow one, the recent past is outrunning the more distant past and the trend is accelerating. When the two converge, the trend is losing force even if price has not yet turned. That is the whole idea, and it is why MACD is best described as a trend-following tool wearing the clothes of a momentum indicator.
Three series are plotted. The MACD line is the difference between the two averages. The signal line is a short exponential average of the MACD line, which acts as a smoothed reference. The histogram is the gap between them, and because it is the difference of a difference it responds first: the histogram shrinks while the MACD line is still rising, which is the earliest mechanical hint that acceleration is fading.
Traders read four things. A crossover of the MACD line through its signal line is the classic momentum trigger. A cross of the zero line is a different and slower statement: it means the fast average has actually overtaken the slow one, which is the same event as a moving-average crossover on price. Expansion and contraction of the histogram track acceleration. And divergence — price making a new extreme while MACD does not — flags that the new high or low was achieved with less force than the last one.
Because the MACD line is expressed in the price units of the instrument, its absolute value is meaningless across markets: a reading of 4 is enormous on a ten-dollar stock and trivial on an index at five thousand. Only its shape, its sign and its behaviour relative to its own history carry information. If you need a version that travels between instruments, divide by price or by ATR first.
Against its neighbours, MACD is slower than a raw momentum oscillator such as rate of change and faster than a moving-average crossover on price. TRIX answers a similar question with triple smoothing and far fewer signals; RSI answers a genuinely different one, since it is bounded and measures the balance of gains and losses rather than the spread between two trends.
Calculation
The arithmetic in words, in the order it happens.
Take a fast exponential moving average of the close, conventionally 12 periods, and a slow one, conventionally 26. The MACD line is the fast EMA minus the slow EMA. The signal line is a 9-period exponential moving average of that MACD line. The histogram is the MACD line minus the signal line. Zero on the MACD line means the two averages are equal; a positive value means the fast average is above the slow one.
Source
An AlgoBeamScript implementation of the formula above, written by us from the arithmetic so the code and the calculation agree line for line.
Runs unchanged on the platform and in the AlgoBeamTS runtime. The language reference is in the documentation.
Inputs
Defaults are the values most charting packages ship with. They are conventions, not optimal settings — the right length depends on your instrument and your holding period.
| Input | Default | What it changes |
|---|---|---|
| Fast length | 12 | The responsive average. Lowering it makes the MACD line jumpier and produces earlier, noisier crossovers; raising it toward the slow length flattens the whole oscillator toward zero. |
| Slow length | 26 | The reference average. Increasing it widens the spread the indicator can reach and slows every signal; the ratio between fast and slow matters more than either number on its own. |
| Signal length | 9 | Smoothing applied to the MACD line to create the trigger. Shorter values give more crossovers and more whipsaw; longer values delay every entry but cut the churn considerably. |
| Source | Close | Price series both averages are computed from. Close is standard; typical price is occasionally used on instruments where the closing print is unreliable. |
| MA type | EMA | Most platforms let the two averages and the signal line be simple instead of exponential. Simple averages give a smoother, later oscillator that is closer in spirit to a crossover system. |
How to read it
What practitioners take from the plot. Read these as descriptions of market state, not as entry signals.
- MACD crossing above its signal line
- Momentum has turned up relative to its own recent average. Far more reliable when it happens above the zero line, in the direction of the larger trend, than as a bottom-picking tool below it.
- MACD crossing the zero line
- The fast average has overtaken the slow one — a genuine trend statement rather than a momentum wobble. Slower than the signal cross, and correspondingly less frequent and less noisy.
- Histogram shrinking while price still advances
- Acceleration is fading. This is deceleration, not reversal: trends often decelerate for a long time before turning, so it argues for trailing a stop rather than for reversing.
- Price at a new high, MACD peak lower than the last
- The new extreme was reached with less force than the previous one. Worth noting, unreliable alone — divergences can repeat several times before price responds.
- Line hovering around zero with frequent crossovers
- The two averages are entangled and the market has no trend. Every crossover here is noise and costs money.
Limitations
Where this indicator misleads. None of these are fixed by a better parameter.
- It is built from two smoothed averages, so it lags. Signals arrive after a meaningful part of the move has already happened, which is inherent to the construction and not fixable by tuning.
- In sideways markets the line oscillates around zero and produces a continuous stream of crossovers that lose money on spread and commission alone.
- Its values scale with the price of the instrument, so thresholds copied from one market to another are meaningless and historical extremes are not comparable across a stock split or a large repricing.
- The histogram tempts traders into calling turns early, before any structural level has broken; a shrinking histogram in a strong trend is normal and frequently resolves upward.
Educational reference. This page explains how an indicator is built and how it is commonly read. It is not investment advice, not a recommendation and not a signal service. No indicator is profitable on its own — each is a way of describing a market, and any rule built on one has to be tested with realistic costs before it is traded.