US stocks recovered from a late-afternoon slide to eke out small gains on 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% 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," Mr 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%, to 18,533.05. The Standard & Poor's 500 index rose 0.85 points, or 0.04%, to 2,181.74. The Nasdaq composite index gained 12.34 points, or 0.2%, to 5,225.48. That's up less thean 0.1% from its most recent high last Friday.
For the year, the Dow is now up 6.4%, while the S&P is up 6.7% and the Nasdaq is up 4.4%.
The stock market has bounced back in recent weeks, buoyed by strong job growth in the US, 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 US Bank's private client reserve.
On Tuesday, US 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 US, 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% 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 dollars to 22.16 dollars.
Valeant Pharmaceuticals surged 25.4% 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 dollars.
Chemicals company Chemours and solar energy seller Vivint Solar also rose after posting better-than-expected earnings. Chemours added 99 cents, or 10.6%, to 10.30 dollars. Vivint gained 30 cents, or 9.4%, to 3.49 dollars.
Retailers did not fare as well.
Gap sank 6.3% after reporting lower sales in the second quarter and in July. The stock dropped 1.61 to 24.01 dollars. Kohl's also fell, shedding 1.67 dollars, or 4.2%, to 37.70 dollars. Target slid 2.39 dollars, or 3.2%, to 72.61 dollars.
Home furnishing store Wayfair slumped 19.6% after posting a wider-than-expected loss in the second quarter. The stock slid 9.45 dollars to 38.80 dollars.
Investors shrugged off a Labour Department report indicating that American workers' productivity unexpectedly fell in the second quarter.
An early rally in US crude oil prices evaporated. Benchmark US crude fell 25 cents, or 0.6%, to close at 42.77 dollars per barrel in New York. Brent crude, used to price international oils, slid 41 cents, or 0.9%, to close at 44.98 dollars per barrel in London.
The slide in oil weighed on several oil and gas companies. NRG Energy fell 69 cents, or 5.1%, to 12.83 dollars, while Southwestern Energy shed 51 cents, or 3.6%, to 13.61 dollars. Chesapeake Energy also declined, losing 20 cents, or 4%, to 4.81 dollars.
In Europe, Germany's Dax rose 2.5%, while France's CAC 40 gained 1.2%. Britain's FTSE 100 added 0.6%.
Markets in Asia where mostly higher. Japan's Nikkei 225 rose 0.7%, while South Korea's Kospi climbed 0.6%. Hong Kong's Hang Seng index fell 0.1%, while China's Shanghai Composite Index gained 0.7%. Stocks in Australia, Taiwan and the Philippines were higher.
In other energy trading, wholesale petrol slipped two cents to 1.35 a gallon dollars, while heating oil lost a penny to 1.33 dollars a gallon. Natural gas fell 13 cents, or 4.8%, to 2.62 dollars per 1,000 cubic feet.
In metals trading, the price of gold rose 5.40 dollars, or 0.4%, to 1,347 dollars an ounce. Silver added five cents, or 0.2%, to 19.85 dollars an ounce. Copper slipped two cents, or 0.7%, to 2.15 dollars a pound.
Bond prices rose. The yield on the 10-year Treasury note fell to 1.55% from 1.59 late on 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 dollars.