For equity it will not work, didn't read it all.
Maybe you use maxVal on a static var.

Max value for last 48 hours and put it into a static var.