Hi, I do not know if I correctly understood, but yo can do it in many ways:
Open 2 trades with half of the size and set the take profit accordingly
Set trailing accordingly with your calculation
Code a TMF that make all the calculation you want and close half of the position

Ciao