Mql4 Code to close drawdown trade to equal previous profits

 

Is there a way to write code that will close your trade with the highest drawdown only once there are ten trades open and the profits from other trades equal the trade with the highest drawdown?

Example: I have ten sell trades open (all in drawdown). The Code/EA should only act once this happens.
Then buy trades are opened and are closed in profit. 
Once the total closed profits of these buy trades are equal to or exceed the drawdown of the worst performing sell trade the sell trade should be closed to break even with the accumulated profits of the previous buy trades.

Reason: