There is a solution for a similar problem in the following post:
I need to do a very simple task: record maximum and minimum values. I want some node to compare the current value with the previous one and see if it is bigger or smaller. If so, return and update the maximum and minimum values. Otherwise, retone null.