(AP) -- U.S. stocks recovered from a late-afternoon slide to eke out small gains Tuesday, nudging the Nasdaq composite to its second record close in less than a week.
The three major stock indexes, all of which set new highs last Friday, rebounded from a slight decline on Monday.
Investors focused on the latest batch of company earnings, bidding up health care, telecommunications and consumer-focused companies most.
Energy was the biggest laggard, as crude oil prices closed lower, backtracking after an early rally. Traders also sold off shares in big department store chains after The Gap reported lower sales figures.
With nearly 90 percent of S&P 500 companies having already reported, earnings this quarter have been OK, while revenue growth has not been as bad as expected, said Bob Doll, chief equity strategist at Nuveen Asset Management.
"We're slowly turning the corner and exiting (the) earnings recession," Doll said. "The worst quarter, year-over-year, was the first quarter. While the second quarter wasn't great, it was less bad. The third and fourth quarters will continue that."
The Dow Jones industrial average added 3.76 points, or 0.02 percent, to 18,533.05. The Standard & Poor's 500 index rose 0.85 points, or 0.04 percent, to 2,181.74. The Nasdaq composite index gained 12.34 points, or 0.2 percent, to 5,225.48. That's up less 0.1 percent from its most recent high last Friday.
For the year, the Dow is now up 6.4 percent, while the S&P is up 6.7 percent and the Nasdaq is up 4.4 percent.
The stock market has bounced back in recent weeks, buoyed by strong job growth in the U.S., improved company earnings and persistently low inflation and interest rates.
"That all equals support for the market, but then the reality is where do we go from here?" said Mike Baele, senior portfolio manager with U.S. Bank's Private Client Reserve.
On Tuesday, U.S. stocks got a boost early on from a rally in European markets and in Asia, where most of the indexes closed higher.
Data out of China showing that consumer price growth declined in July for the third month in a row helped fuel expectations among investors that Beijing will pump out more stimulus in a bid to soften the slowdown in the world's second-largest economy.
In the U.S., stock indexes edged higher until about mid-afternoon, when crude oil prices reversed course after an early surge. The indexes wavered between small gains and losses the rest of the day before they turned higher in the final minutes of trading.
Traders bid up shares in several companies that posted strong quarterly results.
Endo International vaulted 21.8 percent a day after the medical device maker reported that it returned to profit in the second quarter. The Dublin-based company's shares gained $3.97 to $22.16.
Valeant Pharmaceuticals surged 25.4 percent after the Canadian drugmaker reaffirmed its earnings outlook for the year, despite reporting a wider second-quarter loss. The company also said it is undergoing a restructuring. The stock added $5.71 to $28.16.
Chemicals company Chemours and solar energy seller Vivint Solar also rose after posting better-than-expected earnings. Chemours added 99 cents, or 10.6 percent, to $10.30. Vivint gained 30 cents, or 9.4 percent, to $3.49.
Retailers didn't fare as well.
Gap sank 6.3 percent after reporting lower sales in the second quarter and in July. The stock dropped $1.61 to $24.01. Kohl's also fell, shedding $1.67, or 4.2 percent, to $37.70. Target slid $2.39, or 3.2 percent, to $72.61.
Home furnishing store Wayfair slumped 19.6 percent after posting a wider-than-expected loss in the second quarter. The stock slid $9.45 to $38.80.
Investors shrugged off a Labor Department report indicating that American workers' productivity unexpectedly fell in the second quarter.
An early rally in U.S. crude oil prices evaporated. Benchmark U.S. crude fell 25 cents, or 0.6 percent, to close at $42.77 per barrel in New York. Brent crude, used to price international oils, slid 41 cents, or 0.9 percent, to close at $44.98 per barrel in London.
The slide in oil weighed on several oil and gas companies. NRG Energy fell 69 cents, or 5.1 percent, to $12.83, while Southwestern Energy shed 51 cents, or 3.6 percent, to $13.61. Chesapeake Energy also declined, losing 20 cents, or 4 percent, to $4.81.
In Europe, Germany's DAX rose 2.5 percent, while France's CAC 40 gained 1.2 percent. Britain's FTSE 100 added 0.6 percent.
Markets in Asia where mostly higher. Japan's Nikkei 225 rose 0.7 percent, while South Korea's Kospi climbed 0.6 percent. Hong Kong's Hang Seng index fell 0.1 percent, while China's Shanghai Composite Index gained 0.7 percent. Stocks in Australia, Taiwan and the Philippines were higher.
In other energy trading, wholesale gasoline slipped 2 cents to $1.35 a gallon, while heating oil lost a penny to $1.33 a gallon. Natural gas fell 13 cents, or 4.8 percent, to $2.62 per 1,000 cubic feet.
In metals trading, the price of gold rose $5.40, or 0.4 percent, to $1,347 an ounce. Silver added 5 cents, or 0.2 percent, to $19.85 an ounce. Copper slipped 2 cents, or 0.7 percent, to $2.15 a pound.
Bond prices rose. The yield on the 10-year Treasury note fell to 1.55 percent from 1.59 late Monday.
In currency markets, the dollar fell to 101.90 yen from 102.47 yen on Monday, while the euro strengthened to $1.1107 from $1.1083.