Indexes rose from the opening of trading following encouraging quarterly results from Wal-Mart Stores and the media giant Viacom, then flitted up and down most of the day. After four weeks of healthy gains for stocks and a series of record daily closes, the tepid trading was not unexpected.
All three major U.S. indexes closed higher after a late-afternoon rally. The Dow Jones industrial average rose 40.59 points, or 0.2 percent, to 17,652.79, a record. It was the seventh record close for the blue-chip index in eight trading days.
The Standard & Poor’s 500 index rose 1.08 points, or less than a tenth of a percentage point, to 2,039.33. The Nasdaq composite rose 5.01 points, or 0.1 percent, to 4,680.14.
A slump in the energy sector held back the overall market as oil prices continued to slump over fears that supplies will outstrip demand. Benchmark U.S. crude lost 4 percent and is trading at a four-year low.
Energy stocks closed down 1.4 percent, after being off more 2 percent earlier in the day.
Energy company shares trimmed their losses after a late-day report from the Wall Street Journal that Halliburton is in talks to buy rival oil-field service company, Baker Hughes, citing unnamed sources. Baker Hughes soared $7.77, or 15 percent, to $58.75.
In other deal news, DreamWorks jumped 14 percent on a New York Times report that the toy maker Hasbro is trying to buy the company. And Berkshire Hathaway, run by billionaire Warren Buffett, said it was buying the Duracell battery business from Procter & Gamble in a deal valued at about $3 billion.
Among other stocks making big moves:
• Wal-Mart jumped $3.74 to $82.94 after reporting earnings and revenue that were higher than financial analysts had expected. The 4.7 percent gain was the biggest in the Dow.
• Viacom, which owns the Paramount studio, MTV and VH1, rose $1.95, or 2.8 percent, to $71.20 after its results topped forecasts.
• Amazon rose 1.6 percent following news that it had resolved a bitter, long-running dispute with the book publisher Hachette. Amazon stock gained $4.97 to $316.48.
Benchmark U.S. crude fell $2.97 to close at $74.21 a barrel on the New York Mercantile Exchange. Brent crude, a benchmark for international oils used by many U.S. refineries, fell $2.46 to close at $77.92 a barrel, also a 4-year low, on the ICE Futures exchange in London.
In other energy futures trading on the NYMEX:
• Wholesale gasoline fell 10.5 cents to close at $2.002 a gallon.
• Heating oil fell 8.5 cents to close at $2.362 a gallon.
• Natural gas fell 20.8 cents to close at $3.977 per 1,000 cubic feet.
In metals trading, the price of gold edged up $2.40 to $1,161.50 an ounce. Silver was flat at $15.62 an ounce and copper fell three cents to $2.99 a pound.
U.S. government bond prices rose slightly. The yield on the 10-year Treasury note slipped to 2.34 percent from 2.36 percent on Wednesday.