Global trend function

There was a bug with my previous approach.