If you're losing every time to bad beats AND you honestly couldn't have been able to see them coming, then the answer is simple - Never. Bad luck happens. It doesn't necessarily happen in a nice, neat random fashion. In fact, it rarely does.
If on the other hand you're losing but honestly should have seen that most of these hands were going south, then it's still not necessarily time to quit. But, it is time to take breaks, refresh, relearn and try again when you're feeling positive. Analyze every hand that you lose. Ask yourself - WHY did you lose? What could you have done differently? What WILL you do differently next time?
If you can't win no matter what you do (and you've really tried hard to to improve your game) then maybe it is time to quit, or at least take a long vacation.
However, always think of bankroll management. You may not be able to do much about losing, but you can do something about how much you lose.