MACD Calculator: Moving Average Convergence Divergence
Calculate the MACD line, signal line and histogram from your moving averages, with the formula, a worked example and how to read crossovers.
This MACD calculator subtracts your slow exponential moving average from your fast one, then updates the signal line using the previous signal value. It also calculates the histogram, the gap between MACD and signal. Enter existing indicator values rather than closing-price history. Its Divergence Check cannot confirm chart divergence because the form has no price history; a Trading Signal label is not a prediction.
Use the actual average values, not their periods
MACD means Moving Average Convergence Divergence. An EMA, or exponential moving average, gives more weight to recent observations. The conventional setup uses a 12-period fast EMA, a 26-period slow EMA and a 9-period EMA of MACD for the signal. These periods describe bars on the chosen chart, not necessarily days.
| Input label | What belongs in the field |
|---|---|
| 12-Period EMA | The current numerical value of the fast price average |
| 26-Period EMA | The current numerical value of the slow price average |
| Previous MACD | The MACD value from the immediately preceding bar |
| Previous Signal Line | The signal-line value from that same preceding bar |
There is no closing-price list, symbol selector or adjustable period control in this form. Obtain the average and prior indicator values from the same instrument and timeframe. Entering a period count where an average value belongs produces a subtraction that has little connection to your chart.
For background on the indicator, use the MACD guide. If you compare against a platform that uses a simple average for the signal, its signal and histogram can differ from this EMA-based calculation.
The calculation is a single update
- MACD line = current fast EMA − current slow EMA.
- Signal smoothing weight = 2 ÷ (9 + 1) = 0.2.
- New signal = previous signal + 0.2 × (current MACD − previous signal).
- Histogram = current MACD − new signal.
The previous signal carries information from the earlier series. It is a necessary starting value for this update. An arbitrary starting number cannot reconstruct a chart’s full signal history. Previous MACD is used for the comparisons and labels; it is not substituted for the current fast-minus-slow calculation.
The displayed numerical outputs are rounded to two decimal places. Preserve more precision in your input values when checking a chart, and keep the signal update separate from display rounding. A small difference near a crossover can change a text label.
How to calculate MACD step by step from closing prices
The form above needs the moving-average values already worked out. If you only have closing prices, here is how those values are built. MACD stands for moving average convergence divergence. It uses exponential moving averages (EMAs), which give more weight to recent closes.
Step 1: the smoothing factor
Each EMA has a smoothing factor of 2 ÷ (n + 1), where n is the number of bars. For the 12-bar EMA that is 2 ÷ 13, about 0.1538. For the 26-bar EMA it is 2 ÷ 27, about 0.0741. For the 9-bar signal it is 2 ÷ 10 = 0.2, the same weight used in the form above.
Step 2: the seed value
An EMA needs a starting value. A common choice is the simple average of the first n closes, so the first 12-bar EMA is the average of the first 12 closes, and the first 26-bar EMA is the average of the first 26. Charting platforms may seed differently, and that is one reason your numbers can differ from theirs.
Step 3: update each EMA
From then on: new EMA = previous EMA + smoothing factor × (new close − previous EMA).
Step 4: MACD, signal and histogram
- MACD line = 12-bar EMA − 26-bar EMA.
- Signal line = 9-bar EMA of the MACD line.
- Histogram = MACD line − signal line.
A short worked example
Assume, for this example only, that after the seed period the previous 12-bar EMA is 100, the previous 26-bar EMA is 98, the previous signal is 1.8, and the next close is 103. All of these are made-up numbers.
| Step | Calculation | Result |
|---|---|---|
| New 12-bar EMA | 100 + 2 ÷ 13 × (103 − 100) | 100.46 |
| New 26-bar EMA | 98 + 2 ÷ 27 × (103 − 98) | 98.37 |
| MACD line | 100.46 − 98.37 (using unrounded values) | 2.09 |
| New signal | 1.8 + 0.2 × (2.09 − 1.8) | 1.86 |
| Histogram | 2.09 − 1.86 | 0.23 |
Now assume the following close is 101. The 12-bar EMA becomes 100.54, the 26-bar EMA becomes 98.57, MACD becomes 1.98, the signal becomes 1.88 and the histogram falls to 0.10. MACD stays above the signal, but the gap has narrowed, so the histogram shrinks. This is how the histogram bars change in size on a chart.
To use the form above for the first bar, enter the new 12-bar EMA and 26-bar EMA from steps 3 and the previous MACD and previous signal from the bar before.
MACD formula in a spreadsheet
You can build the whole series in Excel or Google Sheets. Put closing prices in column B from row 2. In this layout, the first 12-bar EMA sits in C13 and the first 26-bar EMA sits in D27, because each needs enough earlier closes for its seed.
- First 12-bar EMA (C13): =AVERAGE(B2:B13)
- Next 12-bar EMA (C14): =C13+(2/13)*(B14-C13), then copy down.
- First 26-bar EMA (D27): =AVERAGE(B2:B27)
- Next 26-bar EMA (D28): =D27+(2/27)*(B28-D27), then copy down.
- MACD (E27 onward): =C27-D27
- First signal: the average of the first 9 MACD values, then =F35+(2/10)*(E36-F35) and copy down.
- Histogram: =E36-F36
Check one row by hand against the example above. If a single row matches, the formulas are right. Keep the closing prices to full precision and round only the display.
MACD settings for intraday and swing trading
The default setting is 12, 26 and 9, which comes from the periods in the formula above. Those numbers describe bars, so on a daily chart they are days and on a five-minute chart they are five-minute bars. They are not tuned to any market.
- Shorter periods, such as 6, 13 and 5, react faster to price. They also give more crossovers, and more of them can be false.
- Longer periods react more slowly. Signals come later and there are fewer of them.
- Timeframe changes the meaning more than the periods do. A crossover on a one-minute chart and on a daily chart are different events.
No setting is shown here to perform better. If you want to compare settings, test them on the same instrument and period, with costs, and record the results. A journal that tags the setup lets you see how each setting performed for you. Related reading: how to use the MACD indicator.
Why your calculation differs from TradingView
- Seed value: the first EMA may start from a simple average or from the first close.
- History length: an EMA never fully forgets old data. A chart that loads more history can show slightly different values from one that loads less.
- Signal type: some platforms let you pick a simple average for the signal instead of an EMA.
- Price source: closing price is typical, but a chart can be set to another price.
- Rounding: rounding every step instead of only the display builds up small errors.
To find the cause, compare the fast EMA, slow EMA and signal one at a time, starting from the oldest bar both sides share.
Worked example: check each component
Made-up input example: 12-Period EMA ₹1,250, 26-Period EMA ₹1,200, Previous MACD 35 and Previous Signal Line 40. These are invented values for an arithmetic demonstration, not observations from a named stock.
| Component | Calculation | Result |
|---|---|---|
| Current MACD | 1,250 − 1,200 | 50 |
| Signal update | 40 + (50 − 40) × 0.2 | 42 |
| Histogram | 50 − 42 | 8 |
| Previous histogram | 35 − 40 | −5 |
The previous MACD was below its signal, while the current MACD is above the updated signal. That is a bullish signal-line crossover in these assumed observations. It describes a change between bars; it does not establish that the next price will rise.
Notice also that the current MACD is positive. This means the fast average exceeds the slow one. A positive MACD and a positive histogram answer different questions: the first compares price averages, and the second compares MACD with its own signal.
Above zero, above signal and crossing are different
A MACD can remain below zero while moving above its signal. In that case the fast price average is still below the slow one, even though their relationship has improved enough for a signal-line crossover. A label containing “bullish” therefore needs its reference point explained.
Likewise, being above the signal is not automatically a fresh crossover. Confirm where both lines stood on the previous bar. The example includes Previous MACD specifically so you can distinguish the relationship today from the change since the preceding observation.
The histogram is a signed gap. A negative histogram becoming less negative moves toward zero, even though its numerical value rises. Avoid treating every “expanding” label as stronger momentum in the direction of an existing trend.
For the method’s broader trading context and possible false starts, read the MACD crossover guide. The arithmetic here cannot establish how any entry rule performs after charges.
Divergence Check has too little information
A proper price-versus-indicator comparison needs matching peaks or troughs across time. This form has neither a current-price input nor earlier price swings. Its Divergence Check uses a hidden fallback price, so the displayed label cannot verify divergence in your instrument.
A divergence observation compares how price and the indicator move across corresponding swings. Simply knowing that the fast average is above the slow average does not supply those swings. Keep the relevant chart and describe the observations yourself rather than treating the card as a completed chart review.
Signal Strength also uses fixed absolute histogram thresholds. The same numerical gap can have a different scale on different instruments. Its category is not a measured probability of a winning trade and does not determine an acceptable position size.
Zero values and chart mismatches
Previous MACD and Previous Signal Line can genuinely be zero. This implementation replaces an entered zero with stored defaults. That changes crossover comparisons and, for a zero previous signal, changes the signal calculation itself. Check zero-boundary cases outside this tool.
- Confirm fast and slow values come from the same completed bar.
- Use the immediately preceding signal value, not the signal from a different timeframe.
- Check whether your chart uses an exponential moving average or a simple moving average for each line.
- Check the source series and earlier calculation history when otherwise matching settings differ.
- Keep the observed crossover separate from any later entry and actual traded price.
A MACD reading supplies no stop-distance loss budget. Use the risk-reward calculator for planned price distances, and log your setup and actual decision with the price action journal approach.
MACD calculation questions
Sources
- Fidelity: MACD calculation and default periods, checked 15 Oct 2026.
- TradingView: MACD, signal, histogram and divergence, checked 15 Oct 2026.
- TradingView: EMA calculation, checked 15 Oct 2026.
- Current MACD calculator form, checked 15 Oct 2026.
Related Topics
Related Articles
Absolute Returns Calculator: Total Gain or Loss
Absolute return calculator with formula, worked rupee examples and a comparison with CAGR and XIRR. Learn when absolute return misleads, such as for SIPs.
Options Rollover Calculator
Work out the debit or credit of rolling an option from premiums and lots. Learn roll up, down and out, charges, STT, and futures rollover cost and percentage.
Options Probability Calculator: Model Inputs and Limits
Estimate an option's expected move and price range from price, volatility and days to expiry, with a worked example and why the probability cards need care.
Trading Expectancy Calculator: Formula and Example
Trading expectancy calculator (EV per trade) from win rate, average win and average loss. See R-multiples, profit factor, sample size and low win-rate examples.
Trading Emotion Tracker: Review Feelings and Plan Discipline
Free trading emotion tracker. Log the mood, intensity and plan discipline behind a trade, get a simple rule-based score, and keep a record to review later.
Revenge Trading Detector: Check Your Next Decision
Revenge trading signs, the psychology behind it and a free manual detector. The score uses your answers only, and its rupee cards use assumed amounts.
The trading journal for Nifty, Bank Nifty and Indian F&O. Track your trades, spot patterns, build discipline.
- Log one trade a day by hand, on purpose
- AI mentor finds your repeat mistakes
- Behavioural analytics catch tilt early
- Trading calendar with P&L heatmap
- Pre-trade checklist flags risks
Yearly ₹3,499 · No broker credentials