MACD is a moving-average crossover expressed as a number instead of two lines. Gerald Appel built it in the late 1970s. Rather than asking whether the fast average is above the slow one, it reports the distance between them, so you can see the gap widening or closing. The call is @MACD(close, 12, 26, 9).
How it is computed
MACD = EMA(close, 12) - EMA(close, 26)
signal = EMA(MACD, 9)
histogram = MACD - signal
Three series come out of one call. The MACD line is the raw gap, the signal line is a smoothed version of that gap, and the histogram is the difference between the two. A rule names which of the three it wants to compare against.
The output is in rupees, since it is the difference between two rupee prices. That has a consequence worth internalising: a MACD of 12 on TCS at ₹3,900 and a MACD of 12 on a ₹90 stock describe completely different moves. The simplest rule tests the sign:
@MACD(close, 12, 26, 9) > 0
To compare the indicator across a Nifty 500 universe you have to divide out the price level first, which the grammar allows directly:
@MACD(close, 12, 26, 9) / close > 0.01
Typical parameters
| Expression | Fast / slow / signal | Character |
|---|---|---|
@MACD(close, 12, 26, 9) | the standard triple | the default in nearly all charting software |
@MACD(close, 5, 35, 5) | wider separation | slower, fewer crossings |
@MACD(close, 8, 17, 9) | tighter | faster, noisier |
The 12, 26 and 9 come from a six-session trading week in 1970s US markets, roughly two weeks, one month and half a month. NSE has traded five sessions a week for decades. The numbers persisted because charting packages shipped them as defaults, not because anyone re-derived them.
How to read the output
A positive MACD means the 12-period EMA sits above the 26-period EMA. That is a description of the recent price path, restated. The histogram crossing zero is arithmetically identical to the MACD line crossing its signal line, so treating those as two confirming signals double-counts one event.
Risks and caveats
Every criticism of moving averages applies here twice over, because MACD is built from two of them and then smoothed a third time. It lags, and in a range-bound market it whipsaws. A stock oscillating in a band will produce a stream of crossings, each one costing brokerage, STT and slippage.
Four parameters, three of them windows, over one price history is a large search space. Optimising all four on the same period and reporting the best result is overfitting with extra steps.
MACD is descriptive. It summarises what two averages have already done. Whether that summary carries tradeable information on Nifty 500 names is a question a backtest with realistic costs answers, and the answer may well be no.