Changed valley detection algorithm