NEW YORK (AP) — This month's sell-off for stocks marked the first big test of investors' mettle in years. And many ended up doing exactly what the experts were recommending: hold steady.

Even as stock markets tumbled around the world, putting a halt to an unusually calm and strong ride upward, many investors resisted the urge to sell in a panic and lock in the losses. Others plugged even more cash into their trading accounts after seeing prices for S&P 500 index funds drop by 10 percent within a couple weeks.

At Fidelity's retail brokerage, for example, customers continued to put in more buy orders than sell orders after the S&P 500 began falling from its peak set on Jan. 26. Younger investors led the charge into stocks.

"Millennials and Gen Xers are definitely taking advantage of these prices and taking advantage of the sell-off," said Scott Ignall, senior vice president and head of online brokerage technology at Fidelity.

Experts typically recommend that investors stay the course when stocks go through a bout of volatility. Stock prices can suddenly bounce up and down, as they did this month when the S&P 500 followed up its worst week in two-plus years with its best week in five years. But stocks aren't supposed to be short-term holdings, and they've historically delivered better returns than other investments when held for the long term, such as a decade.

Beyond that, many voices along Wall Street were encouraging investors to "buy this dip." Worries about higher inflation and interest rates sparked the sell-off, but many analysts said they expected corporate earnings and the global economy to stay strong, which should help stock prices recover.

The buying likely played a role in what's been a quick rebound for stocks. As of Friday's close on Wall Street, the index had roughly halved its loss and is down only 4.9 percent from the record.

Consider what millennials customers were doing in their Fidelity brokerage accounts from Jan. 26 through Feb. 12, when the S&P 500 lost nearly 8 percent. Of every $100 in new dollars and money getting re-allocated, $87 went into stocks or stock funds. That indicates an even stronger appetite for stocks than millennials had shown in the placid, record-setting year before the sell-off, when $75 of every $100 went to stocks.

Generation X investors showed an even more pronounced preference for stocks during the downturn, with stocks making up $86 of every $100 in new and re-allocated dollars. That's up from $67 in the prior year.

Older investors were also buying stocks, but at a lower rate than their younger counterparts, and at a lower rate than they had been buying at during the year before the downturn. Baby boomers instead put much more money into money markets and cash.

"Every investor is different, with different goals and risk tolerance, so it's hard to say whether their activity is right or wrong," Ignall said. But "having a plan, sticking to it and being able to adapt to that plan is the most important thing for our clients, and I'm glad they're able to do that through these market conditions."

Fidelity's figures marry with data from others around the industry. Vanguard, for example, looked at how much trading individual investors and 401(k) participants were doing during the tumultuous run from Feb. 2 through Feb. 9. Ninety seven percent did nothing, with nary a trade.

At TD Ameritrade, younger investors also led the way in buying as markets tumbled. Through the first week or so of February, millennials deposited 1.5 times more into their accounts than Generation X and five times more than baby boomers, said JJ Kinahan, chief market strategist at TD Ameritrade.

All this comes with the caveat that many market watchers along Wall Street are warning of continued volatility. After their unusually calm 2017, markets are bound to be jumpier given that the Federal Reserve is raising interest rates and slowly winding down the stimulus it put in place after the Great Recession.

Put another way: This sell-off may have been the first test for investors in a while, but more are coming.