close all orders

 
i would like code for closing all my orders if profit is > than margin
is it possible that order number can be the only factor that program need to know to close it.
because the number of lots is changing.it is not constant.
and then to delete all by and sell limit


thanks