It's not an easy time to be an investor, and if you're feeling conflicted about the stock market right now, you're not alone. On the one hand, the S&P 500 is up more than 7% so far this year, which has many investors feeling optimistic. But on the other, experts are still sounding the alarm that a recession may be imminent, which could result in stock prices falling yet again.

If you're thinking about investing right now, is that really a safe move? Here's what history says.

The future looks bright for the market

When it comes to the future of the stock market, there's good and bad news. The bad news is that nobody can predict how stocks will perform in the near term, so it's anyone's guess whether the market will be up or down a month from now.

The good news, though, is that the market's short-term performance isn't nearly as important as its long-term potential.

Over the last century, the market has faced countless bouts of volatility -- some of them severe. In the last two decades alone, we've experienced the dot-com bubble burst, the Great Recession, the crash in March 2020, the current downturn, and many smaller corrections in between.

^SPX Chart

^SPX data by YCharts.

Despite everything, though, the S&P 500 is still up by more than 180%. In other words, if you had invested in an S&P 500 index fund in January 2000 and simply held your investment, you'd have nearly tripled your money by today -- despite all these major downturns.

The market may experience more volatility in the coming months, but that's OK. There's a very strong chance that, over time, it will earn positive average returns. By sticking it out for the long haul, it's far less likely you'll lose money.

The key to keeping your investments safe

Maintaining a long-term outlook is critical in times like these, but it's equally important to ensure you're setting yourself up for success with the right investments. If the market takes a turn for the worse, not all stocks will be able to recover. But stocks from healthy companies are much more likely to survive a recession or bear market, even if they take a hit in the short term.

The healthiest companies will have solid underlying business fundamentals, such as strong finances, a competent leadership team, and a competitive advantage in their industry. The more of these stocks you have in your portfolio, the better your chances of seeing positive returns over time.

When in doubt, you may opt for a fund that tracks the S&P 500, such as the Vanguard S&P 500 ETF (VOO 0.11%). These types of funds aim to mirror the performance of the index itself. Because the S&P 500 has a long track record of surviving downturns, it's extremely likely this fund will also thrive over the long term.

Regardless of where you invest, try not to get too caught up in the market's daily fluctuations. It can be tempting to sell your investments or avoid the stock market entirely during periods of volatility, but that can sometimes do more harm than good.

If you sell your stocks when prices are lower, you'll end up selling at a discount and locking in those losses. Then if you reinvest after the market rebounds, you'll be paying a premium for the same investments you just sold. But by keeping your money in the market, you can simply wait for your stocks to recover without losing anything.

If history shows us anything, it's that this, too, shall pass. By investing in the right places and holding those investments for the long term, you can rest easier knowing your money is as protected as possible -- regardless of what the future may hold for the market.