You can do this with my objectScript() expression function, thanks to its built-in state dictionary. Something like this:
objectScript("args[0] if not args[1] or state['mx'] is None or args[0] > state['mx'] else state.mx\nstate['mx'] = __retv",
{path/to/value/to/track}, {path/to/condition/boolean})
Note the buried new-line code that ends the expression and provides an opportunity to execute the assignment into the state
dictionary.
The above passes the value through when the condition is false, then captures max while true.