Wall Street capped a choppy day of trading Wednesday with more gains for stocks as investors sized up a mix of company earnings reports and another flare-up in tensions between Washington and Beijing.

The S&P 500 gained 0.6%, its fourth gain in a row, after wavering between gains and losses for much of the afternoon. Strength in technology and health care stocks outweighed losses in energy companies, banks and elsewhere in the market. Treasury yields fell slightly, a sign of caution in the market.

“It’s a relatively muted day in terms of volatility,” said Bill Northey, senior investment director at U.S. Bank Wealth Management. “Having come off a furious rally off the March 23 lows, the market is clearly in a period of consolidation and assessing second-quarter earnings results.”

The S&P 500 gained 18.72 points to 3,276.02. The benchmark index is now within 3.3% of the all-time high it set in February. The Dow Jones Industrial Average rose 165.44 points, or 0.6%, to 27,005.84.

The Nasdaq recovered from an early dip to add 25.76 points, or 0.2%, to 10,706.13. The Russell 2000 index of small company stocks picked up 2.63 points, or 0.2%, to 1,490.14. Indexes in Europe fell. Asia ended mixed.

Homebuilders marched broadly higher after the National Association of Realtors said sales of previously occupied U.S. homes climbed last month by a robust 20.7%. The gain is an encouraging sign for the housing market after the pandemic caused sales to plummet in the prior three months.

Despite the sharp monthly increase, purchases are still down 11.3% from a year ago, when homes had sold at an annual pace of 5.32 million. Builder NVR led the sector, surging 10.7%.

United Airlines slid 4.2% after reporting that its revenue plunged 87% as the coronavirus throttled air travel. Pfizer rose 5.1% after the U.S. government signed a contract with the company to deliver the first 100 million doses of a COVID-19 vaccine it’s developing by December.

Traders also had their eye Wednesday on a flare-up in tensions between Washington and Beijing. The U.S. ordered China to close its consulate in Houston, saying it was necessary to protect American intellectual property. China said it would retaliate.

U.S.-China trade relations will probably start to factor back into the market somewhat, but the virus and its impact remain the main driver of where the markets go, said Liz Ann Sonders, chief investment strategist at Charles Schwab.

“A lot of what we’re looking for rests on whether consumption can stay afloat,” she said. “Even absent additional shutdowns, what are the implications of the fear factor, of consumers just opting to not go out as much?”

The Federal Reserve’s efforts to support markets and expectations that Washington eventually will deliver more financial aid to help Americans weather the economic downturn have been key in keeping markets mostly pushing higher since stocks plunged in March.

Still, worries remain that the rise of coronavirus counts across much of the country will derail efforts to reopen businesses shut down due to the pandemic.

Adding to unease Wednesday was a report by the U.S. Centers for Disease Control that the number of coronavirus cases in some states is much higher than has been reported. Experts have said all along that the toll from the COVID-19 pandemic is much higher than tallies of confirmed cases would indicate, due to issues with testing and data collection.

Uncertainty over prospects for more financial aid to Americans and U.S. businesses also is casting a shadow, analysts said. Republicans and Democrats remain divided over how much support is needed, as states grapple with rebounds in cases that have prompted some local governments to order some businesses to close to help snuff out flare-ups of the virus.

“The market is anticipating that there will be something, what the final (package) looks like is a different question,” Northey said. “Ultimately, we expect some agreement that provides another round of stimulus support.”

Those earnings, so far, have been coming in moderately better than expected, though companies have worked to lower expectations.

HCA Healthcare jumped 12%, the biggest gain in the S&P 500, after reporting earnings and revenue that topped analysts' forecasts.

Among big companies reporting results this week: Intel, AT&T and Twitter report on Thursday and Verizon Communications and American Express report earnings Friday.

The yield on the 10-year Treasury note fell to 0.59% from 0.60%.

Gold for August delivery rose $21.20 to $1,865.10 an ounce, another sign that investors were shifting some of their holdings to traditionally less risky assets.

The price of benchmark U.S oil for September delivery fell 6 cents to settle at $41.90 a barrel Wednesday. Brent crude oil for September delivery fell 3 cents to $44.29 a barrel.

Copyright 2020 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed without permission.