J.K. Rowling is a wealthy author, famous for wizard wars and transfiguration charms. She certainly doesn't seem to have much in common with fellow-billionaire Warren Buffett.

And yet something she said during a commencement speech at Harvard in June can help you become a better investor.

No, really
Rowling's speech was about two things: failure and imagination. As many people know, she has known her share of failure en route to becoming a literary sensation:

By any conventional measure, a mere seven years after my graduation day, I had failed on an epic scale. An exceptionally short-lived marriage had imploded, and I was jobless, a lone parent, and as poor as it is possible to be in modern Britain, without being homeless. The fears my parents had had for me, and that I had had for myself, had both come to pass, and by every usual standard, I was the biggest failure I knew.

And although she found failure far from ennobling, she pointed out that few of us can escape it. "Some failure in life is inevitable. It is impossible to live without failing at something, unless you live so cautiously that you might as well not have lived at all -- in which case, you fail by default," she said.

Want an illustration of that last point? I'm currently taking ice-skating lessons, and I've yet to fall. That may seem like a good thing, a sign of my proficiency. But it's not. It's a sign that I'm not risking enough, not trusting in what my teacher says. I'm skating too conservatively, and I'm progressing slowly because of that. If I would skate more boldly, I'd learn more quickly what works and what doesn't -- even if I fall a few times in the process.

So how is this about investing?
One of the ways we skate conservatively in investing is to sell too quickly: to lock in modest gains for fear they'll disappear or to make sure we don't lose any more than we already have. We're afraid of the big loss, so we fail to let our investment thesis really play itself out.

But look at the returns for some of the best-performing companies of the last 10 years:

Company

10-year Return (1/1/98-1/1/08)

Worst Year's Return

Best Year's Return

Copart (NASDAQ:CPRT)

1,328%

(51%)

169%

Green Mountain Coffee Roasters (NASDAQ:GMCR)

3,389%

(45%)

525%

Immucor (NASDAQ:BLUD)

2,893%

(81%)

346%

Middleby (NASDAQ:MIDD)

1,862%

(54%)

282%

PotashCorp (NYSE:POT)

993%

(25%)

202%

Urban Outfitters (NASDAQ:URBN)

1,095%

(71%)

214%

Valero Energy (NYSE:VLO)

878%

(32%)

141%

On the way to market-beating returns, each one of these companies saw fantastic years and horrible years -- and everything in between. Selling to minimize a loss or to lock in a modest gain would have meant missing all the gains to come.

Selling based on the stock price and the stock price alone, whether up or down, neglects a fundamental truth of the market: volatility. While the market is exceptionally volatile right now, it's always volatile and even the best stocks will occasionally drop substantially.

So sell when the underlying business changes. Sell when you no longer trust the management. Sell when the stock is overpriced relative to the underlying value (not your cost basis). Sell when you realize there was a real problem with your initial investing thesis.

But don't sell just because that volatile stock price is scaring you. Making a habit of it will end up ensuring you fail -- because you'll miss the long-term gains the market has to offer.

What you can do now
Here's the thing: sometimes we will fail. We'll buy the wrong stock, or sell too soon, or sell too late, or miss out on buying that great company we had our eye on. I'm not pointing fingers -- I've certainly failed more than a few times myself (memorably losing $200,000).

But the sign of a great investor is not the absence of mistakes, it's learning from them. As Rowling said in her speech, "The knowledge that you have emerged wiser and stronger from setbacks means that you are, ever after, secure in your ability to survive."

And so, I hope you fail. I hope I do. I hope we both fall on our fannies on the ice, and I hope we'll both continue to learn to become better and more courageous investors.

But if you'd like some help choosing winning companies to hold onto even when you're afraid, let me recommend our Motley Fool Stock Advisor investment service. Fool co-founders David and Tom Gardner's picks have been trouncing the overall market for more than five years now, even in this challenging period. You can even sign up for a 30-day free trial, with no obligation to subscribe, and see all of their recommendations in detail.

Longtime Fool contributor Selena Maranjian does not own shares of any companies mentioned in this article. The Motley Fool is Fools writing for Fools.