MQL4: Close by Opposite Positions?

Hi,
If you have a buy order for 2 lots and a sell order for 1 lots, and your sell order begins to make a profit, I know it is possible to close the sell order in such a way so that the profit goes to lower the investment in the buy order by 1 lot. But how do I do this with MQL4? I could not find anything about this anywhere. The Metatrader 4 help file calls this “Close by Opposite Positions,” but I could find no way to automate it. Can anyone help me out with this?

use the OrderCloseBy function to close an order by an opposite order but I don’t know about the transfering of profit from one to the other I’ve never heard of that