The stock market has been surging over the past year, with the S&P 500 (^GSPC 0.38%) up by more than 45% from its lowest point in late 2022. We're now well into bull market territory, and stock prices don't seem to be slowing down.

This is an exciting time to invest, but the right strategy is key to maximizing your earnings. While there's no one-size-fits-all approach to building wealth in the stock market, there is one mistake that could do much more harm than good.

One common investing mistake to avoid

Although many people are feeling optimistic about the stock market right now, others are worried that perhaps the best opportunity to buy has already passed. Even worse, some investors may be concerned that there's nowhere for stock prices to go but down.

It can be tempting, then, to hold off on investing to see where the market is headed. That may sound like a smart strategy on the surface, but trying to time the market can be incredibly risky -- and it can limit your long-term earnings.

The stock market will always be unpredictable to a degree, so nobody can say exactly how it will perform over the coming weeks and months. If you wait to invest and prices surge, you'll have missed out on those potential earnings. The longer you wait, the more you'll potentially forego.

But what if you invest now and prices drop?

One common fear many investors share is investing right before prices dip. But as long as you keep a long-term outlook, there's never necessarily a bad time to buy -- even if stock prices take a turn for the worse.

For example, say you had invested in an S&P 500 index fund in January 2010. The Great Recession had recently ended and the market was in the early stages of a new bull market, but there were still some significant fluctuations on the horizon. If you had simply stayed invested, though, you'd have earned total returns of nearly 190% within 10 years.

^SPX Chart

^SPX data by YCharts

On the other hand, say you had waited until January 2011 to invest. The market was roughly a year and a half into its bull market, and stock prices had been rising steadily in that time. Yet by 2020, you'd only have earned returns of around 157%.

^SPX Chart

^SPX data by YCharts

Now let's say you waited a little longer and began investing in January 2013. At that point, the market had been surging for several years. It also wouldn't experience any substantial hiccups until late 2015, making it seem like the safest time to buy. However, you'd have only earned returns of around 127% by 2020.

^SPX Chart

^SPX data by YCharts

Market volatility is normal, and it's also impossible to avoid. If you're putting off investing until a "safer" moment, you'll miss out on valuable time to let your money grow.

While it may sound counterintuitive, it's often safer to invest now, no matter what the market is doing. If stock prices drop, simply ride out the storm and stay invested until the market recovers. By waiting for the perfect moment, it will only be harder to see substantial returns over time.

The key to investing success

Keeping a long-term outlook is crucial to maximizing your earnings in the stock market, but it's equally important to choose the right investments. Not all companies will experience long-term growth, and shaky stocks may have a tough time recovering from market downturns.

There's no single correct approach to investing, but the healthiest stocks are the ones from companies with solid fundamentals -- which include everything from strong financials to a competent leadership team to a competitive advantage in the industry.

The stronger your portfolio is, the more likely your investments are to recover from volatility. And the more time you give your money to grow, the more you can potentially earn over time. Regardless of what the future has in store for the market, getting started now will help maximize your potential earnings.