What does this signal filter do? (coming from finance) In finance, many "indicators" are used in order to make prediction about if a price has an increasing or decreasing trend over time.
Among them, MACD is a popular one. There are many slighlty different definitions (standard rolling mean vs. exponential rolling mean, etc.), but one of them is :


the price is $x[n]$   (let's say the sampling rate is 1 second, but we could also use 1 day...)
$y_1[n]$ is the 12-period rolling mean, $y_2[n]$ is the 26-period rolling mean, i.e. :


$$y_1[n] = \frac{1}{12} x[n] + \frac{1}{12} x[n-1] + ... + \frac{1}{12} x[n-11]$$ and the same for $y_2$.


the MACD is defined by $y_1 - y2$, i.e. :


$$macd[n] = \frac{7}{156} x[n] + \frac{7}{156} x[n-1] + ... + \frac{7}{156} x[n-11] - \frac{1}{26} x[n-12] - \frac{1}{26} x[n-13] + ... - \frac{1}{26} x[n-25]$$

Question:

How to have a signal processing interpretation of what's going on with $macd[n]$? I can see it's a linear filter, but how to know what it is doing? Can we draw a frequency response?
It also seems that, because of rolling mean, some lag / delay is introduced.



Remark: When people use MACD, they don't stop with $macd[n]$: they define $signal[n]$ as the 9-period rolling mean of $macd[n]$:

$$signal[n] = \frac{1}{9} macd[n] + \frac{1}{9} macd[n-1] + ... + \frac{1}{9} macd[n-8]$$

and the indicator which is finally used is  (this sounds like a magic trick! why these choices?):

$$h[n] = macd[n] - signal[n] = 
-\frac{14}{351}x[n]-\frac{49}{1404} x[n-1]-\frac{7}{234} x[n-2]-\frac{35}{1404} x[n-3]-\frac{7}{351} x[n-4]-\frac{7}{468} x[n-5]-\frac{7}{702} x[n-6]-\frac{7}{1404} x[n-7]+\frac{2}{27} x[n-12]+\frac{7}{108} x[n-13]+\frac{1}{18} x[n-14]+\frac{5}{108} x[n-15]+\frac{1}{27}x[n-16]+\frac{1}{36}x[n-17]+\frac{1}{54}x[n-18]+\frac{1}{108}x[n-19]-\frac{4}{117}x[n-26]-\frac{7}{234}x[n-27]-\frac{1}{39}x[n-28]-\frac{5}{234}x[n-29]-\frac{2}{117}x[n-30]-\frac{1}{78}x[n-31]-\frac{1}{117}x[n-32]-\frac{1}{234}x[n-33]$$

When $h[n]$ is positive the trend of $x[n]$ is more or less increasing, and when $h[n]$ is negative, the trend of $x[n]$ is more or less decreasing.

Question:

What does $h[n]$ do, with a DSP point of view?
I thought you stock market tech analysts always used moving averages (rolling means) or "exponential moving averagers" for your smoothing operations. Anyway, your $macd[n]$ process is neither of those. As far as I can tell the frequency magnitude response of your $macd[n]$ process looks like the following:



Your $macd[n]$ process does not smooth its input data in the normal sense. It amplifies input data that has a periodicity (repetition rate) of 33.3 days per cycle. In the above plot you can clearly see the "mainlobe" that Fat32 was referring to. If your closing price data contains a periodicity of roughly 33 days then the output of your $macd[n]$ process will be a large value. Otherwise, the output of your $macd[n]$ process will be a small value. I don't know if such a frequency response makes stock market technical analysis sense, or not. 

As for your $h[n]$ process, I believe its frequency magnitude response looks like the following:



Your $h[n]$ process appears to be a process that amplifies input data that has a periodicity (repetition rate) of 21.9 days per cycle. In DSP we use processes like your $macd[n]$ and $h[n]$ for filtering when we want to detect the presence of components in our input signal that have periodicities of 33.3 or 21.9 time units per repetition. We call such processes "resonators" or "bandpass filters."