Investing in the stock market can be lucrative, and it's one of the simplest ways to build life-changing wealth. But if you go into it with the wrong strategy, you could easily lose more than you gain.

While there's no single correct way to invest, there are some mistakes to avoid if you want to maximize your earnings. One pitfall, in particular, is especially common during periods of market volatility, and it could wreak havoc on your long-term savings.

The past couple of years have been a rollercoaster for the market, and with some experts still calling for a recession in the near future, many investors are wondering whether it's best to buy now or hold off until the market stabilizes.

Person with a serious expression looking at a laptop.

Image source: Getty Images.

Although it may be tempting to wait until the perfect moment to invest, that can actually limit your long-term earnings. It may sound counterintuitive, but you can often earn more over time if you continue investing during the volatile periods -- even if your savings take a hit in the short term.

Why timing the market is so risky

The stock market will always be unpredictable in the short term. Case in point: With all the recession warnings in recent months, most people did not expect stock prices to surge -- resulting in some claiming that this is the start of a new bull market.

In other words, there is no perfect time to buy. It's easy to look back in hindsight and consider how much you could have earned had you invested when prices were at rock bottom. But in the moment, it's impossible to know where the market is actually headed.

Even if you buy at the seemingly worst moment, it could still end up being more lucrative than if you wait until a "better" time to invest.

For example, say you had invested in an S&P 500 index fund in January 2009 -- just two months before the market bottomed out amid the Great Recession. That may have seemed like an awful time to invest, as your portfolio would have almost immediately lost value. But over the following two years alone, you'd have seen returns of nearly 40%.

^SPX Chart

^SPX data by YCharts

On the other hand, if you had waited until, say, December 2009 to invest (when the market was already well into recovery mode), you'd only have earned returns of around 13% by January 2011.

Two keys to keeping your money safe

Time is your most valuable resource when investing in the stock market. Even if the market is shaky, you're better off getting started now than waiting for the "right" time to buy.

That said, it's crucial to ensure you're investing in the right places and keeping a long-term outlook.

Stocks from unhealthy companies will have a tougher time recovering from downturns. But stocks from businesses with solid underlying fundamentals -- such as strong finances and a capable leadership team -- are more likely to survive the slumps.

But even strong stocks will often take a hit during periods of volatility, so it's equally important to keep a long-term outlook when investing. Your portfolio may lose value in the short term if the market takes a turn for the worse, but if you stick it out for the long haul, solid investments have a much better chance of earning positive returns.

The market has been rocky over the past couple of years, and nobody can say for certain what the coming weeks or months have in store. But by investing consistently through good times and bad, choosing quality stocks, and keeping a long-term outlook, you can set yourself up for potentially substantial earnings over time.