Can I create an algo for exiting all of my positions by checking MTM ?

This is for exiting option selling setups. For example , I need to exit all legs when my MTM shows 2000 INR loss, or 3000 INR Profit. Is it possible to implment ?