(AP) -- Major U.S. stock indexes eked out modest gains on Monday, extending the market's winning streak into a fourth day.
Stocks wavered into the red at times before steadying in the late afternoon. The price of oil also veered lower at times, but ended higher.
Investors had their eye on the latest batch of company deal news and new data on housing that sent homebuilders broadly lower. Telecommunications services and health care stocks were among the biggest risers.
Monday's action builds on the market's five-week string of gains and suggests an improved outlook by investors since the market's rocky start to 2016. Worries about the global economy prompted the Federal Reserve to slow the pace of interest rate increases this year.
"Investors have really come to terms with the fact that recession risks are receding in the U.S., and that certainly was helped by the Fed action last week," said Mike Baele, senior portfolio manager at U.S. Bank Wealth Management. "We likely move sideways until we get some clarity on earnings."
The Dow Jones industrial average rose 21.57 points, or 0.1 percent, to 17,623.87. The Standard & Poor's 500 index added 2.02 points, or 0.1 percent, to 2,051.60. The Nasdaq composite gained 13.23 points, or 0.3 percent, to 4,808.87.
Thanks to steady gains in recent weeks, the Dow is up 1.1 percent for the year, while the S&P 500 index is up 0.4 percent. The Nasdaq is down about 4 percent.
Stocks had appeared to be headed for a down day early Monday.
Homebuilders fell broadly following a report indicating that sales of previously occupied U.S. homes sank 7.1 percent last month. The trend could weigh on homebuilders, many of which rely on buyers who must sell their home before they can purchase a newly built one. William Lyon Homes was among the biggest decliners. The stock shed 72 cents, or 4.9 percent, to $13.88.
Several companies rose on deal news.
Starwood Hotels & Resorts Worldwide climbed $3.62, or 4.5 percent, to $84.19. Its proposed buyout by Marriott International, which could be contested by China's Anbang, would create the world's biggest hotel company. That likely weighed on fellow hotel operator Wyndham Worldwide, which slid $3.72, or 4.6 percent, to $77.07.
Paint maker Valspar vaulted 23.1 percent on news of its $9 billion sale to Sherwin-Williams. Shares in Valspar rose $29.39 to $103.22. Sherwin slumped $15.40, or 5.3 percent, to $273.29.
Traders also welcomed Markit's decision to combine with competitor IHS in an all-stock deal valued at more than $13 billion. Markit surged $4.02, or 13.6 percent, to $33.51.
Embattled drug company Valeant Pharmaceuticals climbed 7.4 percent as investors cheered a boardroom shake-up that includes plans to replace CEO Michael Pearson and the addition of activist investor Bill Ackman to the board. The stock, which has slid 71.5 percent this year, gained $2 to $28.98.
Oil prices also recovered after dipping earlier in the day.
Benchmark U.S. crude rose 47 cents, or 1.2 percent, to close at $39.91 a barrel in New York. Brent crude, the benchmark for international oils, gained 34 cents to close at $41.54 a barrel in London.
Several energy companies slumped as natural gas lost 8 cents, or 4.1 percent, to close at $1.83 per 1,000 cubic feet.
Williams Cos. shed 80 cents, or 4.4 percent, to $17.35, while Cabot Oil & Gas slid 98 cents, or 4.3 percent, to $21.79. Natural gas transport and storage company Oneok also fell. It was down $1.13, or 3.7 percent, to $29.69.
Market action overseas was mixed.
In Europe, Germany's DAX was essentially flat, while France's CAC 40 fell 0.8 percent. Britain's FTSE 100 slipped 0.1 percent. In Asia, South Korea's benchmark Kospi index slipped 0.1 percent, while Hong Kong's Hang Seng index rose 0.1 percent. Australia's S&P/ASX 200 dipped 0.3 percent. Markets in Japan were closed for a holiday.
In other energy trading, wholesale gasoline added 3 cents, or 2.2 percent, to close at $1.46 a gallon, while heating oil slipped less than a penny to close at $1.24 a gallon.
Among metals, gold dropped $10.10, or 0.8 percent, to $1,244.20 an ounce. Silver fell rose 4 cents, or 0.2 percent, to $15.85 an ounce. Copper rose a penny, or 0.4 percent, to $2.29 a pound.
U.S. government bond prices fell. The yield on the 10-year Treasury note rose to 1.92 percent from 1.88 percent late Friday. The euro fell to $1.1248 while the dollar rose to 111.84 yen.