A late afternoon wave of buying moved U.S. stocks higher Thursday. Even so, the market was on course to finish with a steep weekly loss. Gains in health care and energy companies powered the market higher. It also got a brief boost earlier after President Donald Trump expressed optimism that the U.S. and China will reach a deal to resolve their costly trade dispute. The remarks came as representatives of both countries have resumed talks.

Energy companies rose along with the rice of U.S. crude oil. Large retailers and media and communications companies were the laggards.

KEEPING SCORE: The S&P 500 index rose 11 points, or 0.4 percent, to 2,742 as of 3:25 p.m. Eastern Time. The Dow Jones Industrial Average gained 167 points, or 0.7 percent, to 25,457. The Nasdaq composite added 10 points, or 0.1 percent, to 7,269.45 The Russell 2000 index of smaller companies picked up less than 1 point, or 0.1 percent, to $1,524.89. The stock indexes were on course end the week with a hefty loss. Gainers edged out advancers the New York Stock Exchange.

THE QUOTE: “The market and market participants are more unsettled now than they have been in years,” said Tom Martin, senior portfolio manager with Globalt Investments. “We’re that much further on in the cycle and you have these tariffs and trade wars that are really still in the very early stages.”

US-CHINA TRADE: Investors appeared to draw some encouragement from Trump’s remarks at the White House Friday. Speaking about the lingering trade dispute, the president said he hoped the U.S. could make a deal with China.

“I think a deal will be made,” Trump said. “We’ll find out very soon.”

Stocks snapped higher after the remarks were reported, with the Dow briefly jumping as much as 220 points, before pulling back to about where they were beforehand.

Soybean futures spiked after Trumps’ comments. Soybean prices have fallen sharply since this Spring as the trade dispute with China led to a steep drop in China’s purchases of U.S. soybeans. Soybean futures jumped from $8.83 to $8.92 a bushel following the comments. They had traded as high as $10.78 a bushel in early March.

The Trump administration has imposed a 10 percent tariff on $200 billion of Chinese goods over complaints Beijing steals or pressures foreign companies to hand over technology as the price of market access. That tariff is set to rise to 25 percent in January. Another $50 billion of Chinese goods already is subject to 25 percent duties. Beijing has responded with penalty duties on $110 billion of American goods.

Washington and Beijing resumed talks over their spiraling trade dispute this week ahead of a meeting between President Xi Jinping and Trump, China’s Commerce Ministry said Thursday.

FEELING GOOD: Health care stocks were among the biggest gainers. Universal Health Services gained 3.4 percent to $132.33.

IN STRIDE: Shoe Carnival climbed 5.4 percent to $39.10 after the company reported earnings that were much higher than analysts were forecasting.

CRYPTO FALLOUT: Shares in technology stocks skidded, led by Nvidia. The chipmaker plunged 19.1 percent to $163.70 after saying it had a large number of unsold chips because of a big drop in mining of cryptocurrencies.

SHIELDED? Troubled California power provider PG&E surged 37.9 percent to $24.46 after the president of the utility’s state regulator said it was essential for a power company to have the financial strength to operate safely. The remark late Thursday by California Public Utilities Commission President Michael Picker appeared to reassure investors who have been worried that PG&E is facing severe financial pressure amid speculation its equipment may have sparked the devastating wildfire in Northern California, which started Nov. 8 and has killed at least 56 people.

RETAIL RATTLED: Nordstrom cratered 14.6 percent to $50.40 after the department store issued weak guidance for the full year. That disappointing outlook overshadowed the company’s third-quarter results, which topped Wall Street’s estimates.

UNDERCOOKED: Williams-Sonoma tumbled 12.3 percent to $53.11 after the cookware seller said products were delayed because of shipping congestion out of China ahead of U.S. tariffs.

ENERGY: The price of U.S. crude oil finished flat after a two-day winning streak. Benchmark U.S. crude oil was unchanged at $56.46 a barrel in New York. Brent crude, used to price international oils, gained 0.2 percent to $66.76 a barrel in London. Despite the latest uptick, U.S. crude oil is still down about 13 percent for the month.

The pickup in oil prices helped lift energy stocks. Helmerich & Payne rose 4 percent to $62.45.

In other energy trading, heating oil held steady to $2.07 a gallon and wholesale gasoline jumped 1.3 percent to $1.58 a gallon.

Natural gas, which spiked earlier this week amid forecasts calling for a cold snap across much of the Northeast and South, continued to climb Friday, adding 5.8 percent to $4.27 per 1,000 cubic feet.

BOND YIELDS: Bond prices rose. The 10-year Treasury fell to 3.08 percent from 3.11 percent late Thursday.

CURRENCIES: The dollar fell to 112.87 yen from 113.58 yen on Thursday. The euro strengthened to $1.1409 from $1.1348. The pound rose to $1.2824 from $1.2791.

METALS: The price of gold rose 0.7 percent to $1,223 an ounce. Silver gained 0.8 percent to $14.38 an ounce. Copper climbed 1.9 percent to $2.80 a pound.

OVERSEAS: Major European stock indexes were subdued as trade tensions and political risks surrounding Britain’s exit from the European Union kept investors cautious. Germany’s DAX lost 0.1 percent and France’s CAC slid 0.2 percent. Britain’s FTSE 100 gave up 0.3 percent. In Asia, Japan’s Nikkei 225 index lost 0.6 percent while the Hang Seng in Hong Kong added 0.3 percent. South Korea’s Kospi rose 0.2 percent.