how to book target at all time high ?

Hello i am backtesting this sma50 and sma200 crossover strategy. I want to book profit when price breaks all time high

sma1 = MA ( Close, 200);
sma2 = MA ( Close, 50);
Buy = Cross ( sma1, sma2);