Percent Bar

Overview



{% Trend \; Strength = (close - open) %}
{% PB = \frac{close - open}{high - low} \times (close - open) %}
where the momentum is calculate with the same number of periods, n, as the moving average.

Calculation



The momentum indicator can be fairly easy to calculate. The momentum is just the current price minus the price, n periods ago.


let momentum = data[i].price - data[i-n].price;
					


This calculation more or less ignores the issues that over weekends and holidays.

You can assign a momentum value to each value in an array of prices by using the map function on the array. (similar to the code using a list)


let data = prices.map((p, i, prices)=>{
	if(i>periods) p.momentum = p.price-prices[i-periods].price;
})
					
Try it!


Contents