If the game is good, I stay in until I feel that it is not profitable.
^^^This^^^
If you feel that you are playing your A game and you're at a table that is providing you with good opportunities, there isn't any reason to quit unless you feel that you're getting tired, no longer playing your best game, need to go eat dinner, etc.
I'll also throw in that if you're up an amount that you're happy with, and if you start losing you'll get tilted, there's no law against stopping your game when you feel that you've put in a good session.
Bottom line: totally up to the way you feel. There's no set rule.
You didn't ask about when to quit if losing, but look up the concept of a "stop loss" which is the amount of buy-ins you're willing to lose in a given session. Set a limit according to solid
bankroll management, and stop when you hit it (as opposed to trying to chase after the money you've lost).