Calculate MACD from closing prices or from known fast and slow EMAs, with the signal line and histogram for standard 12/26/9 or custom periods.
Calculator Functions
| Function | What it does | What it requires |
|---|---|---|
| Known EMAs | Finds the MACD value from two exponential moving averages that are already known | Requires the fast EMA and the slow EMA for the same instrument and the same latest period |
| Closing prices | Builds both EMAs from a price history, then finds the MACD, the signal line and the histogram | Requires closing prices from oldest to newest at equal intervals, and a period setting: 12 / 26 / 9, 5 / 35 / 5, 8 / 17 / 9 or custom fast, slow and signal periods |
Prices are separated by commas, spaces or new lines and are typed without thousands separators. Results are in the same price units as the inputs and state whether the MACD is above or below its signal line.
MACD Formulas
| F | Fast exponential moving average (EMA) of closing prices, 12 periods in the standard setting |
| S | Slow EMA of closing prices, 26 periods in the standard setting |
MACD stands for moving average convergence divergence. The MACD line is in the same price units as the two averages.
Known EMAs
The slow EMA is subtracted from the fast EMA. A 12-period EMA of $5.50 and a 26-period EMA of $3.50 give a MACD of 5.50 โ 3.50 = 2.00. A positive value means the fast average is above the slow one, and a negative value means it is below [1]. This function has no signal line or histogram, because those depend on earlier MACD values.
Closing prices
Each EMA is built from the price list in three steps [2]. The first value is the simple average of the first N prices, where N is the period. The weighting multiplier is then:
That is 0.1538 for 12 periods and 0.0741 for 26. Every later price P moves the average by that share of its distance from the previous value:
k ร (P โ EMAprev) [2]
The MACD line is the fast EMA minus the slow EMA at each period where both exist. The other two outputs follow from it [1]:
The signal line is a 9-period EMA of the MACD line in the standard setting, started the same way with a simple average of its first values. With periods of 3, 6 and 3 and the prices 10, 11, 12, 13, 12, 11, 12, 14, 15, 16, the latest fast EMA is 14.9688 and the slow EMA is 13.9165, so MACD = 1.0523. The signal line is 0.7952 and the histogram is 0.2570.
The list needs at least slow period + signal period โ 1 prices: 34 for 12 / 26 / 9, 39 for 5 / 35 / 5 and 25 for 8 / 17 / 9. A shorter list is rejected, and so is a fast period that is not smaller than the slow period. 12, 26 and 9 are the typical settings, and 5 / 35 / 5 is a more sensitive alternative [1].
Limits of This Estimate
- An EMA depends on every price before it, so the minimum number of prices gives a rough value. A charting platform that starts from years of history will show a different MACD for the same day, and far more data than the period length is needed for close agreement [2].
- Prices have to be evenly spaced and in order. Mixing daily and weekly closes, or leaving gaps, changes the result.
- One latest value does not show a crossover, which needs the MACD and signal values from the period before as well.
- MACD describes past prices. It is not a forecast or investment advice, and it is not bounded, so its size cannot be compared between instruments with different price levels.
Sources
- StockCharts ChartSchool, MACD (Moving Average Convergence/Divergence) Oscillator: MACD line, signal line and histogram definitions, the 12, 26 and 9 settings and the 5, 35, 5 alternative
- StockCharts ChartSchool, Moving Averages: Simple and Exponential: the three EMA steps, the 2 รท (N + 1) multiplier and the need for extra history
