Help with code for closing all trades based on net profit of all open trades

mpr  
I'm trying to write code for closing all open trades based on the net profit of all open trades.  The scenario is there are open trades on multiple currency pairs.  One or more of those trades may be at a loss, but the net value of all open trades is positive.  I want the code to close all open trades based on a set desired profit(variable).  Has anyone done this?
Simon Gniadkowski  
mpr:
I'm trying to write code for closing all open trades based on the net profit of all open trades.  The scenario is there are open trades on multiple currency pairs.  One or more of those trades may be at a loss, but the net value of all open trades is positive.  I want the code to close all open trades based on a set desired profit(variable).  Has anyone done this?
Recent posts on this Forum have covered similar scenarios.