Many companies featured on Money advertise with us. Opinions are our own, but compensation and
in-depth research may determine where and how companies appear. Learn more about how we make money.

Traders and financial professionals work on the floor of the New York Stock Exchange (NYSE), July 12, 2016 in New York City.
Traders and other financial professionals work on the floor of the New York Stock Exchange last month.
Drew Angerer—Getty Images

Retirement account balances rose in the second quarter but fell over the past year, new research shows. The year-over-year decline came even as stock prices were mostly flat.

The average 401(k) account balance stood at $88,900 at the end of June, according to an analysis of Fidelity accounts. That was up from $87,300 at the end of March but down from $91,100 a year earlier, Fidelity says. IRA accounts showed a similar pattern: The average balance stood at $89,700 on June 30, up from $89,300 at the end of March but down from $96,300 a year earlier.

The 2.5% decline in 401(k) balances and 7% decline in IRA balances came as the S&P 500 index eked out a miniscule gain. Retirement accounts routinely hold other assets such as cash and bonds, and contributions and distributions also affect account balances. Still, comparing changes in account balances to changes in the stock market is useful for savers wanting to gauge their progress. Moving in and out of stocks at the wrong moments can play a big role in subpar performance.

While stocks showed little net movement over the 12-month period, the market experienced the kind of sharp near-term ups and downs that send some savers to the sidelines. In the second quarter, a 600-point drop in the Dow Jones industrial average was followed quickly by a nearly 800-point gain. Those scared off by the decline may have missed out on the recovery.

Meanwhile, those who stuck to their contribution schedule may have benefited from buying while stocks were temporarily depressed. Buying stocks on a schedule through thick and thin is known as dollar cost averaging—and it boosts returns over a long period when stocks have remained flat or risen.

Target-date funds and other managed accounts have become popular in recent years, partly because they take emotion out of investing. At Fidelity, 45% of 401(k) account holders have all their assets in such a fund and only 1% of them made an investment change over the 12 months. By comparison, 13% of those who pick their own investments made investment changes in the period, Fidelity reports.

Read next: How to Conquer Your Investing Fears in Retirement

Those who have remained continuously employed and had assets in a 401(k) plan for at least 10 years saw their balance rise—not shrink—over the 12 months. This group’s average balance was $241,300, up from $231,500. Such savers are most likely to have stuck with a contribution schedule and benefited from dollar cost averaging. They are also less likely to have taken an early distribution or plan loan.

Millennials often get criticized for their investment choices. But the oldest in this group—those who have been active in a plan for at least 10 years—are making solid progress, Fidelity says. They had a record average balance of $92,900, up nearly 10% from $84,700 a year earlier.