The S&P 500 (^GSPC 0.09%) put all doubts of a bull market to rest when it hit a new all-time high on Jan. 19. Stocks have continued climbing higher through the first half of the year, and the S&P 500 is currently sitting near its peak.

Lofty stock prices may leave some investors nervous about putting their money to work in stocks. After all, every bear market, by definition, begins just after stocks reach an all-time high, so it feels like you could end up buying just as the market's fortunes reverse.

But buying stocks when the S&P 500 hits a new all-time high has historically been a smart strategy. It may be a great opportunity to invest your extra money in the stock market right now.

Person looking at charts on a computer and a phone.

Image source: Getty Images.

The most recent all-time high won't be the last

There's a good reason almost everyone recommends investing in the stock market to grow your wealth. Stocks, as a group, increase in value over time faster than just about any other asset class.

Since stocks tend to go up over the long run, that means they'll continually reach new all-time highs. And one all-time high typically leads to another in short order.

Since reaching a new all-time high on Jan. 19 earlier this year, the S&P 500 has posted a new intraday high 30 more times this year. That number of new record highs isn't uncommon, either. The S&P 500 has posted 40 or more new record highs in a single calendar year nine times since the 1980s. And since we hit a new all-time high in January, this is far more likely to be one of those years with a large number of new record highs.

Not only do stocks typically continue climbing higher after reaching a new high, they actually climb faster than average. The S&P 500 has averaged a 12.7% return in the 12-month periods following an all-time high. It averaged just 12.4% returns for all other 12-month periods, according to data analyzed by Fidelity Wealth Management. If you sold your stocks when the index hit a new all-time high, you'd potentially miss out on a lot of returns.

The S&P 500 index currently sits about 13% above the all-time high it reached in January. That may leave some investors worried the current bull market is about to run out of steam. But remember, the statistic above describes the average for all new all-time highs. Some will have much better one-year returns -- like the first in a string of new all-time highs -- and some will have much worse one-year returns, like the last in a string. There's still a lot of room to run in the current bull market.

That's readily apparent if you step back further. Investing on the day stocks hit an all-time high between 1988 and 2020 led to a total return of 50.4% after three years and 78.9% after five years, according to data analyzed by JPMorgan. That bests the average three- and five-year returns of the S&P 500 of 39.1% and 71.4%, respectively, during that same period.

Investors can still earn very strong returns even as stocks continue to set new records over and over again.

The best way to invest when stocks hit a new all-time high

Even when the stock market is trading near its all-time high, some companies' stocks are bound to present a better value and potential returns than others. Spotting those opportunities may be more difficult as more and more stocks zoom higher, but it's possible to find them in just about any market environment.

For those who don't want to dive into individual companies' stocks and build a diversified portfolio on their own, it's hard to go wrong investing in a broad-based index fund like the Vanguard S&P 500 ETF (VOO 0.15%). The fund has a track record of tightly following the S&P 500, and it charges one of the lowest expense ratios in the industry.

The current bull market has been driven by the returns of just a few company's stocks. The "Magnificent Seven" have played an outsized role in generating new all-time highs for the S&P 500. The top three companies in the index -- Nvidia, Microsoft, and Apple -- currently account for roughly 21% of the entire index.

Investors who want a more diversified portfolio should consider an index fund that tracks the S&P 500 equal weight index, such as the Invesco S&P 500 Equal Weight ETF (RSP 0.12%). The index weighs all 500 components of the S&P 500 equally and rebalances quarterly, meaning Nvidia, Microsoft, and Apple never account for much more than 0.6% of the fund's holdings.

There are dozens of ways to put your money to work while stocks are trading at an all-time high. If you want to grow your wealth over the long run, you can't balk when stock prices climb higher and hope for a pullback. The odds are good that stocks will continue to climb, and you'll miss out on years of great returns.