The short, simple answer is that you exit when your system/plan tells you to exit.
If your system/plan doesn't tell you when to get out, you need to do further work on it. The exit should fit with the reasons and objectives for getting into the trade.