The notion of "quitting while you're ahead" is ridiculous if you are trying to play legit poker. The money will come in the long term if your game is solid.
Having said that, I stop playing when I'm tired or when I am just plain having a bad day. When tilt starts to set in, no matter how good you might be about managing your emotions, they will affect you in some way (they affect everyone) so it's best to walk away before you lose even more.
Be aware of "positive" tilt as well...don't become complacent!