A whopping 70% of the stocks in the S&P 500 are in positive territory this year. And it doesn't look like the market's going to turn direction anytime soon. Meaning it could be time to take some money off the table.

But knowing when -- and how -- to sell is one of the most difficult investing decisions.

Just ahead, I'll outline four key criteria you should use when determining whether you should sell a stock, and then spell out two different ways to do so. But first, let's look at why selling is so difficult.

Breaking up is hard to do
Cognitive dissonance makes us uncomfortable. Really uncomfortable.

Cognitive dissonance is that feeling you get when you know you shouldn't do something, but you also know that it feels damn good. It's the feeling you get when deciding whether or not to order KFC's 540-calorie Double Down sandwich. It's also the feeling you get when you're up 100% on a stock that you were once down 50% on. You swore you'd sell when you broke even, but now you're thinking of holding on for another 100%, or maybe another 200% ... on maybe you'll just wait and see where you are a few months from now

If you've ever been in that last scenario (and if you're like me, you probably have a few stocks like that in your portfolio right now), it's a good idea to have hard-set rules for when to sell a stock. That way your easily swayed emotions don't get prevent you from selling.

Here are four criteria that you should use when determining whether or not to sell.

1. Better opportunities
Whether you're up, down, or at break-even with a stock in your portfolio, if you come across a more attractive opportunity, you should seize it.

What qualifies as a more attractive opportunity? Two things: A stock that's more undervalued than a current holding, or a stock that's valued about the same, but has a lower level of risk.

For example, let's say you bought large-cap Bank of America (NYSE: BAC) since it bottomed out in March 2009. You knew that the bank franchise was stronger than the market was giving it credit for. And you agreed with hedge fund manager David Tepper that shares could go to $27 per share.

Today you'd be up roughly 200%. But given the recent headlines surrounding errors in the foreclosure process at banks like Bank of America, you might be getting nervous and considering selling.

Then you run across a small-cap regional bank like Union First Market Bancshares (Nasdaq: UBSH) -- which, in full disclosure, I bought shares of not long ago. The largest community bank in Virginia, it has conservative lending practices, a strong balance sheet, and has a safe dividend of 1.8%. Not to mention, value investing legend Tom Gayner bought shares of it not long ago.

They're both trading right around book value, but given the absence of headline risk, the conservative policies and its strong dividend, Union First is -- in my opinion -- the better stock to own right now.

2. Valuation
It's a smart move to have some rules in place regarding selling based on a company's valuation.

Amazon.com (Nasdaq: AMZN) might have seemed a reasonable investment when it was trading below $40 per share back at the end of 2008, but now that it's nearing $200 with a P/E ratio of 68, it's not nearly as attractive, and might be overvalued.

The same holds true for Chipotle Mexican Grill (NYSE: CMG). At the end of 2008 it also dipped below $40 per share. It recently topped $200 on a strong earnings report, and now carries a P/E ratio of 40. Though the burritos are addictive and growth seems strong, it's become a "market darling," which often makes a stock risky to hold.

If you own either Amazon or Chipotle, it's probably time to at least begin taking some money off the table, and looking for more undervalued opportunities.

3. The business changes
There's only so much you, as an outsider, can know about a company. Take the shake-up at Satyam Computer Services (NYSE: SAY-WD) in early 2009. When it was announced that executives were engaged in accounting fraud, assumptions you had about past business cycles, the current state of business, and even expectations for the future were no longer trustworthy. In this scenario, it's usually best to take your losses or gains and move on.

4. Wrong investment thesis
Sometimes the reason you believe a company will succeed doesn't play out.

Hypothetically take Netflix, which despite looking overvalued like Amazon and Chipotle (it has a P/E ratio north of 60, following a huge run-up over the past year), you might still be holding shares of, anticipating that it will become the clear dominant player in the online video on demand sector. If tomorrow the company announced it was exiting the streaming video field, instead focusing solely on growing its core movie-by-mail business, it would be wise to sell, take your gains, and move on.

Just letting go
When you are ready to sell, you can either do so gradually, or do so completely. When it's a valuation issue, it's usually best to move out of the position gradually, in case the stock still has more near-term upside. But when the business radically changes, your investment thesis is wrong, or you see a clearly better opportunity, selling in one fell swoop is often the best move.

Even though these are the criteria I use when deciding whether to sell, the criteria I've outlined above are -- truth be told -- not something I came up with myself. Rather, I've adopted it from the team at Motley Fool Million Dollar Portfolio.

The team members use these four reasons when deciding whether to sell a stock in their real-money newsletter service. Not only do they tell members exactly when to begin forming a position in a company they find attractive, but also they perform the more difficult task of telling members exactly when to sell, using the unemotional criteria I just shared.

If you're interested in monitoring their live, real-time, real-money advice, we're about to reopen its doors for the last time this year. To find out more information, or to be notified when it opens to the public, just click here.

This article was originally published Oct. 29, 2009. It has been updated.

Adam J. Wiederman owns shares of Union First, but of no other companies mentioned above. Chipotle Mexican Grill is a Motley Fool Rule Breakers recommendation. Amazon.com and Netflix are Motley Fool Stock Advisor selections. Chipotle Mexican Grill is a Motley Fool Hidden Gems pick. We Fools may not all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors. The Motley Fool has a disclosure policy.