Investing in the stock market can be incredibly nerve-wracking, especially during periods of volatility. However, it remains one of the simplest and most effective ways to generate long-term wealth.

If you want to earn as much as possible, though, you'll need the right strategy. While there's no single correct way to invest, even seemingly small mistakes can be costly over time.

There's one mistake that can be particularly detrimental to your savings, and it's common during periods of market turbulence: trying to invest at just the right time.

Timing the market isn't worth the risk

It's normal to want to invest at the exact right moment, especially when you look back at previous downturns. If you'd invested heavily when the market reached its lowest point and then sold the moment prices peaked you'd have made a hefty profit.

In reality, though, it's impossible to know where the market is headed in the short term. Case in point: Many investors didn't expect the market to surge the way it has over the last several months, especially with recession alarms ringing right and left. And experts are divided right now over how long this upswing might last.

^SPX Chart

^SPX data by YCharts.

If you try to time the market and your bet is wrong, it could be costly. Say you predict stock prices are going to fall in the coming weeks, so you pull your money out of the market now. If the market ends up surging, you'll miss out on those potential earnings.

Then if you decide to reinvest later after prices have already increased, you'll end up paying a premium for the exact same investments you just sold. Mistiming the market even once could potentially cost you hundreds or even thousands of dollars, but doing this repeatedly over a lifetime could be far more expensive.

A safer (and more rewarding) strategy

Fortunately, there's a safer way to make money in the stock market, and it's much simpler than trying to invest at just the right moment. It's called dollar-cost averaging.

Dollar-cost averaging involves investing consistently throughout the year, regardless of what the market is doing. Sometimes, you'll invest when prices are sky-high; other times, prices will be much lower. Over time, those highs and lows will average out.

This strategy can not only save you the hassle of trying to determine when to invest, but it could also save you lots of money. When you're investing consistently throughout the year, you can take advantage of the market's low points without worrying if you're buying at precisely the right time.

The final key to investing success

Dollar-cost averaging makes it easier to avoid losing money in the market by buying at the wrong time, but it's equally important to ensure you're investing in the right places. Stocks from healthy companies make the best long-term investments, as they're the most likely to see consistent growth over time.

While there are never any guarantees when it comes to the stock market, businesses with solid fundamentals (such as healthy financials, a knowledgeable leadership team, and a competitive advantage in the industry) have better chances of pulling through downturns and seeing long-term success.

By filling your portfolio with strong stocks, you won't need to worry as much about when, exactly, to invest. Even if the market takes a turn for the worse, these stocks are more likely to rebound. And by investing consistently, you can take the guesswork out of when to buy and set yourself up for potentially significant earnings over time.