The average shareholder probably won't outdo the S&P 500 this year, according to Louis Harvey, president of Dalbar, a Boston research firm.The problem is that millions of investors are dumping funds. Struggling to pay their mortgages, hard-pressed homeowners are taking money out of their IRAs. Panicked shareholders are selling stock funds and buying Treasuries. The timing of these moves couldn't be worse, says Harvey. When investors sell into a downturn, they lock in losses and miss out on the eventual rallies. "When the market is going down, you should be buying," he says. Harvey should know. For two decades, he has been tracking the behavior of fund investors. All too often people buy when the market is peaking and sell near the bottom. One of the most dramatic examples of mistiming occurred in the 1990s when Janus Twenty ( JAVLX) rose and fell. In 1997, the fund had $6 billion in assets and an annual return of 29.7%. Seeing the giant results, investors poured into the fund, which reached $36 billion in assets by 1999. But the newcomers had arrived just in time for the collapse that came in 2000, when the fund lost 32.4%. The bad behavior explains why many fund investors get miserable results, Harvey says. During the 20 years ending in 2007, the average equity fund shareholder had an annual return of 4.5%, more than seven percentage points behind the S&P 500. The outlook for fund investors is not all bleak. In recent years, a growing percentage of assets has been coming into funds through 401(k) plans and other retirement accounts. Most 401(k) investors dollar-cost average, putting in set amounts each month. As a result, the plan participants buy shares on dips, a process that boosts long-term returns, says Harvey. The flood of cash into retirement plans helps explain why the average equity investor returned 7.1% in 2007, nearly 2 percentage points better than the S&P.