Scaling out half positions and moving rest positions to breakeven?

I have an AFL in which if I buy 1000 stock at lets say $20 and put the stop loss at the low of the candle which is $19. So the risk is $1 here. I want to sell hald of the stocks (500) at 21 and then move the rest of the stocks cost to breakeven i.e $20
Can you please tell me how to do it ?

You can start by reading these articles

https://www.amibroker.com/guide/h_pyramid.html
related / similar:
http://www.amibroker.com/kb/2016/01/28/how-does-risk-mode-trailing-stop-work/
http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/