How to hold variable value at max price instead of moving with price?

Hi, I’m creating a strategy for trailing stop.
I have a variable (TrailPrice) that records price after it moves 20 points in profit.
For example, once price> 20 points, TrailPrice = Close - 10.
Then I have a stop order at TrailPrice. I see the sell order pop up when it happens at 10 points below current price.
However, if the price moves down, it moves the trailprice down as well.
How can I make this variable so it never goes below the max price so I always have a stop at 10 points below the highest price?
Thank you

So. The price on your trailing stop is not locked to the new ratchet point. Take your code and stick it into Googles Gemini Pro 2.5 AI, and ask it to figure it out. That is where I live all day long, everyday. Also tell the AI to explain the code to you in elaborate detail.

In case of bullish:
TrailPrice = Math.Max(Close - 10, TrailPrice)
Bearish:
TrailPrice = Math.Min(Close + 10, TrailPrice)

Thanks but I’m using strategy builder for this.
Basically, trying to build a strategy that replicates ATM trailing stop that’s there on manual orders.

Any idea on doing this with strategy builder?
I want partial trailing as the strategy takes profit at certain points and leaves remaining on trailing stop.
thanks

Update: I found MAX indicator kind of works so I’ll play around with it and see if that’s good enough.