The stock market has been one of the best ways to build your nest egg, but it's not always a smooth ride. As the Federal Reserve aggressively hiked rates in 2022, asset prices tanked. But 2023 was a turnaround year, and the optimism has carried over so far into 2024.

The Dow Jones Industrial Average, one of the most closely watched indexes, was up 12% in 2023. And on Feb. 23, it was up 2% for the year, and the popular index of 30 blue chip companies had hit a new all-time high.

Are you wondering if it's time to buy stocks now?

Always play the long game

If you've been sitting on the sidelines watching the market keep rising, it may be discouraging knowing that you're missing out on potential gains. You might assume that the smart strategy isn't to buy right now but to wait until things cool off before jumping in.

This idea makes sense. Why would you put money into stocks when you think they could drop in the near future? No one likes to lose money.

This is a flawed approach, though. We all think we can correctly time the market, missing the worst days and taking advantage of the best days. But doing this profitably on a consistent basis is a losing game. You're likely to do more damage to your portfolio by buying and selling at the worst times.

On the other hand, this means that it's better to just buy and hold now. In the last 50 years, the Dow Jones has produced an average annual return of 8%. Even if you invested at a fresh peak, over the very long term, you'd still earn close to this average gain. That's very encouraging.

By understanding this reality, investors can accept that the great advantage they have is time. The earlier you start putting money to work, the better off you'll be -- even if the market seemingly hits fresh all-time highs each day.

Ways to gain exposure

You've correctly decided that you don't want to try and time the market. Now you have to figure out how you'd like to gain exposure to the stock market, one of the greatest wealth-building tools available.

Buying index funds is a strategy that even the great Warren Buffett suggests is what the vast majority of people should do. There is a top low-cost option that tracks the Dow directly, the SPDR Dow Jones Industrial ETF Trust (DIA 0.36%). If you want to gain exposure to the S&P 500 or the Nasdaq Composite index, there are numerous other choices that can give you access to the holdings in these indexes, as well.

If you believe that you have the time and the required skills to analyze individual securities, it might be a good idea to look at certain stocks to buy right now. As I mentioned earlier, the Dow Jones consists of 30 companies that are recognized leaders in their respective industries with long and successful operating histories. Among them, there are a few names that stand out.

Tech-giants Apple and Microsoft should be on every investor's radar. They sell some of the most popular products and services in the world. Both companies are incredibly profitable and have seen their share prices skyrocket in the last decade.

But based on Apple's and Microsoft's forward price-to-earnings ratios of 35 and 28, I view their shares as being expensive today. Still, both stocks should be on your watch list because they are undoubtedly some of the most dominant companies on Earth.

Investors shouldn't be discouraged that the market is hitting highs. Now is as good a time as ever to start putting some money to work.