(Reuters) - Wall Street gained for a fourth straight session on Tuesday, its longest winning streak since January, buoyed by the energy sector as oil prices rebounded from early declines.
Oil prices were initially lower on concerns a deal between Iran and six global powers would result in more supply, but turned higher after it became apparent sanctions on Tehran's crude exports would not be removed immediately.
"The big news is clearly in the oil markets and the fact there was an agreement reached," said David Lefkowitz, senior equity strategist at UBS Wealth Management Americas in New York.
"There is still, frankly, a lot of uncertainty about exactly what it will do in terms of oil supply."
The S&P energy sector .SPNY advanced 0.8 percent, led by a 0.8 percent gain in Exxon Mobil Corp (XOM.N) to $83.11. Brent LCOc1 settled up 1.1 percent to $58.51 and U.S. crude CLc1 settled up 84 cents to $53.04 a barrel.
Gains were broad, with nine of the 10 major S&P 500 sectors ending higher, led by a 1 percent gain in the healthcare index .SPXHC. The Nasdaq biotech index .NBI jumped more than 2 percent to hit a record high for the second time in three weeks.
The Dow Jones industrial average .DJI rose 75.9 points, or 0.42 percent, to 18,053.58, the S&P 500 .SPX gained 9.35 points, or 0.45 percent, to 2,108.95 and the Nasdaq Composite .IXIC added 33.38 points, or 0.66 percent, to 5,104.89.
Investors have shifted focus to corporate profits as the pace of quarterly results begins to pick up speed, diverting attention from the debt crisis in Greece and the massive selloff in Chinese stocks.
U.S. companies are expected to report their worst sales decline in nearly six years when they post second-quarter results, while earnings are expected to have fallen 2.8 percent, according to Thomson Reuters estimates.
JPMorgan (JPM.N) and Wells Fargo (WFC.N) helped lift financials .SPSY by 0.4 percent after posting quarterly results. JPMorgan rose 1.4 percent to $69.04 and Wells Fargo climbed 0.9 percent to $57.25.
Twitter (TWTR.N) jumped as much as 8.5 percent after a false report, attributed to Bloomberg LP, that the social media company received an offer to be acquired for $31 billion. Bloomberg and Twitter said the report was fake and the stock ended the session up 0.9 percent at $36.72.
Micron Technology (MU.O) jumped as much as 12.7 percent to $19.84 and was the biggest gainer on the S&P 500. China's state-backed Tsinghua Unigroup Ltd is preparing a $23 billion bid for the U.S. memory chip maker, Reuters reported, in what would be the biggest Chinese takeover of a U.S. company.
NYSE advancing issues outnumbered declining ones 1,934 to 1,089; on the Nasdaq, 1,769 issues rose and 1,032 fell.
The S&P 500 posted 44 new 52-week highs and 2 new lows while the Nasdaq recorded 137 new highs and 34 new lows.
Volume was light, with about 5.5 billion shares traded on U.S. exchanges, well below the 6.8 billion average so far this month, according to data from BATS Global Markets.
Reporting by Chuck Mikolajczak; Editing by Nick Zieminski