How to modify second order

I open two orders for a buy position, one of them hits TP and one’s left open. How do I write an EA to modify the open trade to move SL to break even then begin trailing?

I’ve tried solving this for days, but it seems very tricky. I need help.