algorithms for calculating trends (6)