The stock market has been on a wild roller-coaster ride over the past couple of years, and if you're feeling nauseated by all the ups and downs, you're not alone.

Currently, the S&P 500 is up by nearly 18% so far this year and around 26% from its lowest point last October. While many people are optimistic that this is the start of a new bull market, others remain skeptical, especially since the long-awaited recession still isn't off the table.

If you're feeling conflicted about whether to invest right now or wait, it can sometimes be helpful to look to the experts.

While nobody can say for certain where the market is headed in the short term, legendary investor Warren Buffett can offer some reassuring words when it comes to investing during periods of volatility.

Is it safe to invest right now?

While the market's short-term movements can be daunting, they generally shouldn't affect your strategy. Even if stock prices fall in the coming weeks or months, it's still a good idea to invest now.

The stock market will always be unpredictable in the near term, and even the experts can't say where prices will be in the coming weeks or months. So if you're waiting for the perfect opportunity to invest, that moment might never arrive. 

In the long term, though, the market is incredibly resilient. Over the past two decades alone, it has experienced multiple major recessions, countless corrections, and plenty of other ups and downs along the way. Yet the S&P 500 is still up by more than 207% since 2000.

^SPX Chart

^SPX data by YCharts.

In short, as long as you're a long-term investor, it doesn't necessarily matter what the market is doing today, next week, or even next month. Over many years, it's extremely likely it will see positive total returns.

Buffett's best advice for surviving volatility

This long-term investing strategy is also Warren Buffett's go-to approach, especially during periods of volatility.

In 2008, at the height of the Great Recession, Buffett wrote an opinion article for The New York Times to help reassure worried investors. In it, he explained that he was continuing to invest in stocks even as prices plummeted.

"Let me be clear on one point: I can't predict the short-term movements of the stock market," he wrote. "What is likely, however, is that the market will move higher, perhaps substantially so, well before either sentiment or the economy turns up. So if you wait for the robins, spring will be over."

While it might sound counterintuitive, investing consistently during the market's rough patches can actually be more lucrative over time than waiting for the perfect time to buy. Many stocks are still priced well below their peaks, meaning now is your chance to load up on quality investments at a fraction of the cost.

"In short, bad news is an investor's best friend," Buffett wrote in the Times article. "It lets you buy a slice of America's future at a marked-down price."

One key to ensuring your investments thrive

Continuing to invest throughout the market's ups and downs is only one part of the equation. It's equally important to make sure you're investing in the right places.

The key to choosing the right stocks is to focus on companies with solid underlying business fundamentals -- such as healthy finances, a capable leadership team, and a competitive advantage in their industry. These stocks will still often take a hit in the short term when the market is volatile, but there's a good chance they will recover.

This is also Buffett's tried-and-true approach when buying stocks. In a 2021 letter to Berkshire Hathaway shareholders, he explained the strategy behind his and business partner Charlie Munger's investing success.

"[W]e own stocks based upon our expectations about their long-term business performance and not because we view them as vehicles for timely market moves," he wrote. "That point is crucial: Charlie and I are not stock-pickers; we are business-pickers."

The stock market can be intimidating during periods of volatility. But if you maintain a long-term outlook and choose the right investments, the short-term ups and downs shouldn't affect your strategy. By continuing to invest consistently, you'll be on your way to generating wealth that lasts a lifetime.