Price Minus Moving Averages

Overview


The price minus moving average is an indicator that is often used in determining price trends. The calculation is given as
{% PMMA = Price_t - \sum_{i=t-ma}^t Price_i %}

Use in Technical Analysis



Moving Averages are used in technical analysis as a method of detecting a trend. An asset is said to be in a trend if its current price is higher than a given moving average, for example, a 50 day or 200 day moving average. This is referred to as the price minus moving average rule. The calculation of the moving average requires the specificaiton of a given time frame. (as in 50 days, or 200 days) The time frame chosen is said to indicate the time frame over which the trend has ocurred. A 200 day moving avereage is thought to be more of a long run trend, whereas a 50 day or shorter can be thought as a short term trend.

An alternative calculation would use a short term moving average instead of the price. (see Moving Average minus Moving Average) For example, one could calculate the 20 day moving average minus the 200 day moving average.

Calculation



Calculating Moving Average details various ways to calculate a moving average.

The following shows how to first calculate a moving average of a set of prices, which is then set back on the prices ojects with the name "ma". Next, it uses $list.map to add a new column named "pmma" which is the current price minus the calculated moving average.



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

let data = [{price:100},{price:101},{price:102},{price:101},
		{price:99},{price:102},{price:102},{price:103},];


//calculate the moving averages
let madata = $list(data).mapAppend(p=>p.price,{
	ma:data => ma.movingAverage(data, 3)
}).map(p=>{
	let record = {...p, pmma:null};
	if(p.ma !== null) record.pmma = p.price-p.ma;
	return record;
}).items;
					
try it


Contents