According to the world's best investor, Warren Buffett, the key to getting rich in the stock market can be summed up in 12 words: "Be fearful when others are greedy and greedy when others are fearful."

Given how straightforward this advice is, you may be surprised to learn that most investors aren't any good at buying and selling stocks. A recent analysis of investor returns revealed that over the past 20 years, the average investor underperformed the S&P 500 on an annual basis by 4.2%.

That may not sound like a lot in any single year, but project that over two decades and you're starting to talk about real money. Over the period examined, the S&P 500 returned a total of 543% compared with the average investor's 178%.

The problem is that we make decisions based on emotions. Quite to the contrary of Buffett's advice, we get greedy when stocks are soaring and pile into the market, but then stampede toward the exit after the market crashes. The vast majority of us, in other words, have a knack for buying stocks when they're high and selling them when they're low.

And to make things worse, it doesn't matter how many times we do this. We fail to learn our lesson. At the height of the Internet bubble in 2000, investors poured $315 billion into the market. Then, after stocks lost nearly 50% of their value, we liquidated our holdings and pulled $29 billion out. We then repeated the same pattern before and after the financial crisis of 2008-09, and we're in the process of doing so again.

This is why Buffett says the ability to control one's emotions is the single most important determinant of success in the stock market:

Success in investing doesn't correlate with IQ. Once you are above the level of 25, once you have ordinary intelligence, what you need is the temperament to control the urges that get other people into trouble in investing.

For someone like Buffett, a steady temperament that was tailor-made for investing seems to be genetically ingrained. Many of his biggest stock holdings at Berkshire Hathaway were accumulated when other investors were tripping over themselves to get out of the market.

He bought American Express in the mid-1960s after its share price was cut in half thanks to the Salad Oil Scandal. He purchased shares of Wells Fargo when a real estate crash in the early 1990s led other investors to question its solvency. And he poured billions of dollars into both Goldman Sachs and Bank of America at the depths of the latest crisis.

The question, in turn, is this: How can you steel your own emotions so that you, too, can be greedy when others are fearful and fearful when others are greedy?

The answer is twofold. First, it's important to appreciate that volatility is a frequent and inherent quality of the stock market. As my colleague Morgan Housel points out, the S&P 500 has declined by at least 10% from a recent high 89 times since 1928. That equates to about once every 11 months.

And second, you need to have a plan and resources -- namely, cash -- at your disposal to employ when stocks fall. What sector will you focus on? What stocks will you buy? Not only will answering these questions give you a roadmap to use when the inevitable happens, but the process of doing so will itself also help to temper your emotions.

At the end of the day, successful investing is simple but not easy. You don't have to be a genius. You don't have to immerse yourself in reams of financial statements. You don't have to follow the market on an hourly or even a daily basis. But you do have to recognize your own shortcomings and develop a strategy that neutralizes their impact on your portfolio.