Max min function

Can the max function calculate value based on rolling basis. So my idea is to use max function wrapped with atr to create a trailing stop which does not move down.

You could do something like

runningValue := Max( thisValue, runningValue[1])

But RATCHET() is I think what you are looking for

But how it can be used in script in a backtester.