The stock market has given investors a reason to celebrate this year. All three major indexes are rallying after falling into a bear market in 2022. The S&P 500 has climbed more than 20% from its bear market low, prompting some to even say a bull market has arrived.

But not so fast: To call a bull market, an index should also reach new highs. That hasn't happened yet, and some experts are sounding the alarm that things aren't as rosy as they seem. In fact, a top economist has warned that today's situation looks a lot like the lead-up to past market crashes.

Let's find out more about his comments -- and decide whether you still should invest in the stock market right now.

Three past crashes

President of Rosenberg Research David Rosenberg said the market environment resembles the ones ahead of the 1929 crash, the bursting of the dot-com bubble in 2000, and the financial crisis of 2008. His comments came in a research note this week, according to Markets Insider.

"The balloon does have a lot of hot air in it," he wrote. Rosenberg said that amid the market euphoria, consumers are struggling with rising inflation and finding it hard to borrow money. And a fear of missing out (otherwise known as FOMO) has kept some investors piling into the stock market, just like the periods preceding past crashes.

It's true that stocks have soared even as the economic situation remains complicated. We're still in a higher interest rate environment, which weighs on companies' costs and the consumers' wallets. As a result, corporate earnings may suffer in the months to come, and that might hurt stock performance.

Some economists have become more optimistic in recent weeks, saying the U.S. won't slip into a recession this year after all. Though the inflation rate remains above the Federal Reserve's goal of 2%, it's fallen to its lowest since 2021.

That's encouraging. But at the moment, it's impossible to predict whether the optimistic or pessimistic economic predictions will dominate -- and whether the stock market will continue rising, pull back, or even crash.

So in this sort of situation, should you still invest in the stock market right now?

The risk of short-term investing

If I were investing for just a few days or weeks, I would worry about buying stocks today -- or any day. A short investing window opens up the door to a lot of risk. One bit of bad news, and your holding could decline in value.

But here's the thing: The best way to invest -- and the surest path to great returns -- is long-term investing. This means buying stocks and holding them for at least five years. Over that time period, you may experience declines, but you're more likely to see periods of gains.

So, this means if you do happen to be in the market during a downturn or crash, that's OK. Over the long term, you still can win.

Take a look at the chart below showing the performance of S&P 500 from before the 2008 financial crisis through today. As you can see, the index has more than made up for any losses from even its steepest downturns.

^SPX Chart

Data by YCharts.

Technology stocks, often sensitive during times of market troubles, have shown their resilience over time. For example, Apple, Alphabet, and Amazon have all climbed in the triple digits over the past decade.

AMZN Chart

Data by YCharts.

Time to make up losses and gain

All of this means you shouldn't worry too much about what direction the economy and the stock market take in the coming months. By holding your stocks long term, you give your portfolio the runway to make up any losses and go on to gain further.

Now, you might ask, "Well, why not just wait and buy stocks during the next sell-off?" That's because it's impossible to consistently time the market and buy at the very lowest level. The best idea is to get in when prices look reasonable and the long-term outlook looks good. There are many stocks in this situation today.

So, yes, it can be helpful to listen to what experts have to say -- and avoid stocks that seem overvalued. But any time is the right time to invest when you choose carefully and plan to hold onto stocks for the long haul.