Moving Average Convergence Divergence

Overview


Moving average convergence divergence indicators essentially look at moving averages of different periods and flag when the various moving averages begin to move in different directions.
{% MAC = MovingAverage_{period1} - MovingAverage_{period2} %}
For example, consider a the 20 day moving average minus the 50 day moving average. If the trend is up, this will be a positive number. So far, this is just the moving average minus moving average rule. The MAC rule suggests that when the MAC between two periods is positive, the upward trend is accelerating.
{% MAC_{t} - MAC_{t-1} %}
When the difference is positive, that means the the shorter term moving average is growing faster than the longer term, which indicates acceleration.

Calculation


The following sample code uses the Moving Average Library to calculate two moving averages.


let ma = await import('/lib/time-series/moving-average/v1.0.0/moving-average.mjs');


let av1 = ma.movingAverage(data, 50);
let av2 = ma.movingAverage(data, 20);

let macd = av1.map((p,i)=>{
	if(p !== null) return av2[i] - p;
	return null;
});
					
Try it!


Contents