After a rough couple of years, the stock market is finally surging again. The S&P 500 (^GSPC 0.91%) has been reaching new heights, soaring by a whopping 41% from its lowest point in October 2022.

This can be an exciting time for investors, many of whom have watched their portfolios plummet in value over the past several years. But if you've been hesitant to jump back into the stock market, it may seem like you've already missed the best opportunity to buy.

But is the best of the recovery period really already behind us? Or should you still invest now? Here's everything you need to know.

Is right now a good time to invest?

There's good and bad news about the future of the stock market. The bad news is that the market's short-term performance is unpredictable, and even the experts can't say for certain where stock prices will be weeks or months from now.

The good news, though, is that over the long term, the market is far more consistent. Throughout its history, the market has not only recovered from every single recession, crash, and bear market it has ever faced, but it's also experienced positive long-term returns.

For example, over the past two decades alone, the market has surged by nearly 244%. Even if you hadn't invested during its lowest periods, you still could have earned a substantial amount of money by simply getting in the market at any point and staying invested.

^SPX Chart

^SPX data by YCharts

The key, then, is to keep a long-term outlook and get started investing as soon as possible. The longer you wait, the less you may earn over the long haul.

What if the market is about to dip?

Another common concern among investors right now is that this surge is only a temporary rally and that stock prices are about to fall. While it's unclear where the market is headed in the short term, even if a downturn is on the horizon, that shouldn't deter you from investing.

For instance, say you had invested in an S&P 500 index fund in February 2020 -- just weeks before the market would experience one of its fastest crashes in history. At the time, that may have seemed like the worst possible moment to buy. But by today, you'd have earned total returns of nearly 57%.

^SPX Chart

^SPX data by YCharts

Or, say you invested in an S&P 500 index fund in January 2008. The market was just starting its descent heading into the Great Recession, which wouldn't officially end until mid-2009. Still, though, by simply staying in the market, you'd have earned total returns of 244% by today.

^SPX Chart

^SPX data by YCharts

In other words, as long as you keep a long-term outlook, it doesn't necessarily matter when you buy. The market has consistently climbed over time, and by waiting for the "perfect" moment to invest, you're missing out on valuable time to let your money grow.

The key to keeping your money safer

Regardless of when you choose to invest, it's critical to ensure you're choosing the right investments. Not all stocks will experience long-term growth, and shaky companies may have a tough time recovering from market downturns.

The companies with the strongest fundamentals (which include everything from healthy financials to a knowledgeable leadership team to a competitive advantage) are the most likely to thrive over time. By filling your portfolio with these types of stocks, you stand the best chance of surviving whatever downturns may come your way.

Nobody knows for certain what the market will do in the near future, but with the right strategy, there's never necessarily a bad time to invest. By choosing the right investments and keeping a long-term outlook, you can set yourself up for substantial earnings over time.