If there's one thing every investor learns, eventually, it's that the market goes both up and down. The swings can be dramatic and swift as Wall Street shifts between periods of greed and fear. For long-term investors, an important skill is learning to live with the inherent near-term uncertainty to benefit from the long-term growth of the market -- which is the key to avoiding this expensive mistake.

Moving slowly up and to the right

If you look at a long-term graph of the S&P 500 Index (SPY 0.95%), you'll notice that it has moved fairly reliably higher. However, it is a jagged line, not a straight line. There have been many periods during which this broad stock gauge has fallen with shocking speed, and some points in time where the S&P trended slowly lower -- and others in which it just sort of sat around for a stretch doing nothing at all.

SPY Chart
SPY data by YCharts.

The point is, there is no kind of uniformity in the long trend. Periods of weakness, however, can be hard to endure because fear is a powerful emotion. When the market is crashing, it's easy to succumb to the feeling that you have to save what you have left. The gut response is often to sell stocks.

If you feel like selling everything you own, the first thing you'll probably want to do is ask yourself why. The answer will probably be obvious -- the market is falling -- but having that response at hand allows you to look at what would happen if you were out of the market.

You don't want to miss the best days

On Nov. 17, J.P. Morgan Wealth Management provided some interesting numbers for the year-to-date period in 2023. Over the entire span examined, the S&P 500 rose 19%. But if you weren't invested for the five best return days, you would have had a return of only 8%. Miss the 10 best days, and your return in an ETF tracking the index declines to a loss of 1%. Things get really bad after that, with the loss falling to a 14% and 23% if you miss the 20 and 30 best days, respectively.

SPY Chart
SPY data by YCharts.

That period doesn't even look at a full year, but as the above chart shows, there have been a number of big ups and downs this year. This isn't unique, however, as this theme plays out over the long-term as well.

J.P. Morgan also looked at the period between 2002 and 2022. That's a 20-year stretch that includes both the Great Recession and the coronavirus pandemic. It was, to say the least, an eventful period.

SPY Chart
SPY data by YCharts.

Staying invested over the entire two-decade period would have turned a $10,000 investment into $61,685, according to J.P. Morgan. If you were out of the market for the 10 best days, that figure would have dropped to $28,260. Think about that for one second. If you missed just 10 days out of 20 years, your return would have been cut by more than half. Staying the course has, historically, proved to be a good choice even during periods of extreme market volatility.

Don't try to time the market

When you step back and look at what you risk missing by selling out of fear, the big-picture story is that you don't want to try to time the market. Living through stock market corrections can be hard, but missing the often swift recovery from a steep drop can be seriously detrimental to your long-term returns. The better choice has historically been to grit your teeth and stay invested.