NEW YORK (Reuters) - Wall Street gained ground on Friday in a broad-based rally as investors were heartened by news that Washington would move to temporarily end the longest U.S. government shutdown in history.

All three major U.S. stock indexes advanced, with the Dow and the Nasdaq eking out their fifth straight weekly gains. But the S&P 500 posted its first weekly loss of the year, snapping a four-week run.

The indexes backed off their highs after President Donald Trump confirmed he and lawmakers agreed to advance a three-week stop-gap spending plan to reopen the government.

Investor sentiment had faltered in recent days in the face of revived jitters related to the shutdown and the prolonged U.S.-China tariff spat.

“As some of these uncertainties in the market start to diminish we’ll get a clearer picture as to where things are headed,” said Charlie Ripley, senior market strategist for Allianz Investment Management in Minneapolis. “And today’s news of the ending of the government shutdown certainly alleviates some of that overhang.”

“But most likely some uncertainty will linger as this is only a temporary measure to fund the government for now,” Ripley added.

Among these uncertainties, the ongoing trade dispute between the United States and China continues to worry investors.

With the World Economic Forum in Davos, Switzerland, nearing its conclusion, business leaders have expressed worries over the tariff battles, saying they are “fed up” with Trump’s policies.

An escalation of the U.S.-China trade war would sharpen the global economic slowdown already under way, according to a Reuters poll of hundreds of economists worldwide.

Traders work on the floor of the New York Stock Exchange (NYSE) in New York, U.S., January 22, 2019. REUTERS/Brendan McDermid

Fourth-quarter corporate earnings season is in high gear, with more than 22 percent of S&P 500 companies having reported. Of those, 72.3 percent have beaten analyst expectations.

Earnings on Friday were a mixed bag.

Starbucks Corp also surpassed Wall Street consensus, reporting better-than-anticipated quarterly sales. The coffee chain’s shares advanced 3.6 percent.

Consumer products company Colgate-Palmolive Co reported fourth-quarter revenue that surprised to the upside but said it expects profit to decline in 2019. Its stock edged down 0.6 percent.

Intel Corp shares dropped 5.5 percent following the chipmaker’s disappointing fourth-quarter sales and current-quarter forecasts.

Still, the Philadelphia SE Semiconductor Index ended the session up 2.2 percent in the wake of a spate of positive earnings from other chipmakers.

DR Horton Inc’s quarterly results fell short of analyst expectations, underscoring persistent weakness in the U.S. housing market. The homebuilder’s shares fell 2.6 percent.

Western Digital Corp also disappointed, but its closed 7.5 percent higher after providing an upbeat forecast and saying it was committed to paying dividends.

The Dow Jones Industrial Average rose 183.96 points, or 0.75 percent, to 24,737.2, the S&P 500 gained 22.43 points, or 0.85 percent, to 2,664.76 and the Nasdaq Composite added 91.40 points, or 1.29 percent, to 7,164.86.

Advancing issues outnumbered declining ones on the NYSE by a 3.41-to-1 ratio; on Nasdaq, a 2.56-to-1 ratio favored advancers.

The S&P 500 posted 14 new 52-week highs and no new lows; the Nasdaq Composite recorded 36 new highs and 20 new lows.

Volume on U.S. exchanges was 7.55 billion shares, compared to the 7.79 billion average over the last 20 trading days.