Stocks shock off an early wobble on Wall Street Tuesday, finishing modestly higher and extending the market's gains into a fourth week.
Solid earnings from Walmart encouraged investors to bid up other retailers and consumer goods companies. Communication services stocks and banks also contributed to the broad gains.
Homebuilders also notched gains following an industry survey showing improved confidence among builders heading into the key spring homebuying season.
Roughly 81 percent of S&P 500 companies have reported results for the last three months of 2018, delivering earnings growth of 13.1 percent versus a year earlier, according to FactSet. First-quarter snapshots are expected to result in a 2.5 percent decline in earnings, however.
Even so, the strong quarterly performance from the world's largest retailer was an encouraging signal on U.S. consumer spending after a government report last week showed retail sales slumped in December.
"Now that we're winding down on earnings, investors are looking forward to what's going to move the market higher," said Karyn Cavanaugh, senior markets strategist at Voya Investment Management. "The fact that the consumer is still strong is a comfort to investors."
The benchmark S&P 500 index, which has risen for the past three weeks, gained 4.16 points, or 0.1 percent, to 2,779.76.
The Dow Jones Industrial Average rose 8.07 points, or 0.03 percent, to 25,891.32. The Nasdaq composite added 14.36 points, or 0.2 percent, to 7,486.77. The Russell 2000 index of smaller companies picked up 5.22 points, or 0.3 percent, to 1,574.47.
Major European indexes finished mostly lower.
U.S. stock indexes got off to a downbeat start Tuesday as U.S. markets reopened following the Presidents Day holiday. They wavered between small gains and losses for most of the morning, then veered higher in late morning trading and held on to most of their gains the rest of the day.
London-based bank HSBC and oil and gas rig operator Transocean declined after both companies reported quarterly results that fell short of Wall Street analysts' forecasts. HSBC fell 3.1 percent and Transocean lost 2.2 percent.
But Walmart's results helped lift the market.
The retailer rose 2.2 percent after its quarterly earnings beat forecasts. Walmart benefited from growth in online sales and the expansion of its grocery pickup and delivery business. Amazon gained 1.2 percent, while Target added 1.5 percent.
The latest round of company earnings showed solid profit growth for the final three months of 2018, but caution about conditions going forward amid signs of a weaker global economy this year. Europe and China have both reported slower growth.
Meanwhile, uncertainty over the costly trade conflict between the U.S. and China has also clouded the outlook for company profits.
"We still have that overhang of global growth and trade issues," Cavanaugh said, noting that traders are looking ahead now to company earnings for the first quarter with "a little trepidation."
Beyond the quarterly corporate report cards, investors were keeping a close eye on talks between U.S. and Chinese negotiators in Washington that are aimed at ending a trade war between the world's largest economies.
A truce between the U.S. and China on increased American tariffs on Chinese goods expires at the end of next week, leaving the U.S. free to more than double its import duties on $200 billion in Chinese goods.
President Donald Trump has said there is a possibility he would extend that March 2 deadline if the two countries are close to a deal. Much is riding on the outcome of the talks after an inconclusive end to an earlier round in Beijing last week.
Vice Premier Liu He, China's economy czar, was due to arrive in Washington on Thursday, China's state media reported, after two days of preliminary talks by lower-level officials.
The U.S. is wrangling over trade with many nations. On Monday, the European Union warned that the bloc will hold back on a commitment to buy more American soybeans and liquefied gas if European cars are hit with punitive tariffs.
Investors also bid up shares in homebuilders after an industry survey showed builders are feeling more confident about their sales prospects this month.
The National Association of Home Builders/Wells Fargo Housing Market Index released Tuesday has a reading of 62. That's an increase of four points from last month's index and the highest reading since October.
Readings above 50 indicate more builders see sales conditions as good rather than poor.
William Lyon Homes was among the biggest gainers, adding 3.1 percent.
Bond prices rose. The yield on the 10-year Treasury note fell to 2.64 percent from 2.66 percent late Friday. That yield is used to set rates on mortgages and other kinds of loans.
The dollar rose to 110.66 yen from 110.60 yen on Monday. The euro strengthened to $1.1340 from $1.1312.
Gold climbed 1.7 percent to $1,344.80 an ounce. Silver gained 1.4 percent to $15.97 an ounce. Copper jumped 2.7 percent to $2.87 a pound.
U.S. benchmark crude rose 0.9 percent to settle at $55.09 a barrel in New York. Brent crude, the standard for international oil prices, slipped 0.1 percent to close at $66.45 a barrel in London.
In other energy futures trading, wholesale gasoline dropped 0.6 percent to $1.56 a gallon. Heating oil slid 1.3 percent to $1.99 a gallon. Natural gas gained 1.4 percent to $2.66 per 1,000 cubic feet.