Young man working on laptop © ONOKY-Eric Audras, Getty Images

Today's stock market exhibits plenty of worrisome signs. Stocks of small companies have been sinking, which is often a bad sign for the broader market. Economic growth remains sluggish years after the worst recession since the Great Depression. Vladimir Putin's mischief ultimately threatens the crucial flow of natural gas from Russia to Western Europe.

Why buy now, when the leading market indexes are at record highs?

Because a review of recent history shows that the date you pick to invest doesn't matter that much, even if you invest at the market's highest level of the year.

Sound crazy? Dan Wiener, editor of "The Independent Adviser for Vanguard Investors," compared the records of two hypothetical investors over the past 30 years. Each started by investing $1,000 in the Standard & Poor's 500 index ($INX) at the end of 1983. (Of course, you can't buy an index, but you can invest in a low-cost index fund.)

Over the subsequent 30 years, each investor put $1,000 annually into the S&P 500. But investor No. 1 bought on the last trading day of the year, while investor No. 2 bought at the S&P's highest point each year. In other words, investor No. 2 bought on the worst possible day each year.

Here's the surprise: At the end of 30 years, investor No. 1 had achieved an annualized return of 9.9 percent, while investor No. 2 earned an annualized return of 9.5 percent. The difference in returns was just 0.4 percentage point per year, on average.

In dollar terms, investor No. 1's total contributions of $31,000 grew to $177,176, while the additions of the investor with extremely poor timing grew to $169,153. The difference is $8,023. If you're saving for retirement, you'd hope to invest a lot more than $31,000 over three decades, which would result in a far greater dollar gap.

The difference between the two approaches is significant. But it's not nearly as much as I would have expected, and it puts some perspective into all the agonizing many of us go through before we put new money to work in stocks.

Of course, if you could accurately time the stock market, you could enrich yourself enormously. Over the past five years through April 30, the S&P 500 returned a sizzling 19.1 percent annualized. But from December 31, 1999, through April 30, the index returned only 3.7 percent annualized. So clever market timing would have done far better than buying and holding through this period, which included two vicious bear markets.

In the 2000-02 bear market, the S&P plunged 47 percent, and in 2007-09, it did even worse, sinking 55 percent (both figures include dividends). Since 1926, large-company stocks have returned an annualized 10.1 percent, according to Ibbotson Associates -- almost three times the return so far this century.

Wiener's study provides evidence of the merits of dollar-cost averaging -- that is, investing a fixed amount at regular intervals, in this case once a year. Indeed, if you had invested $1,000 annually in the S&P on the last day of the year from 1999 through 2013, you would have earned a 7.0 percent annualized return by April 30 -- almost double what a one-time, lump sum investment at the start of the century would have produced.

The lesson is clear: Dollar-cost averaging works wonders in volatile markets. But the bigger lesson is even clearer: If you plan to buy stocks this year, go ahead and invest now -- even if you think the market may be at its yearly high.

Click here to become a fan of MSN Money on Facebook

More from Kiplinger