U.S. stocks closed higher in light volume trade Tuesday as second-quarter earnings season began and investors eyed developments in Greece and a slight recovery in oil prices. ( Tweet This )
"I think most of all it's a continuation from yesterday," said Robert Pavlik, chief market strategist at Boston Private Wealth. "I think people are trying to get positioned ahead of earnings."
Fed Chair Janet Yellen's testimony to Congress on Wednesday and Thursday will be watched, but "in the long run I don't think there's anything that comes of it," Pavlik said.
Stocks posted their fourth straight day of gains. The S&P 500 briefly topped 2,110, while the Dow Jones industrial average closed above 18,000. The Dow transports ended 0.07 percent lower.
The Nasdaq Composite outperformed, ending at 5,104, as biotechs surged more than 2 percent, while Apple ended a touch lower. The index has not touched negative territory since July 8. The last time the Nasdaq had four straight sessions without ever falling into the red during intraday trade was in December 2009.
"Yesterday's 1.1 percent rally in the SPX allowed it to break out from a short-term consolidation phase, which we view as a positive technical catalyst," BTIG Chief Technical Strategist Katie Stockton said in a note. "Next and final resistance is at the May high near 2,135, which we believe is surmountable in the weeks ahead."
The Dow swung back into the black for the year on Monday as stocks surged more than 1 percent following news of a bailout deal between Greece and its creditors.
Last week "you tested support perfectly and support held. Right now the absence of bad news (overseas) is good news," said Adam Sarhan, CEO of Sarhan Capital. "The data is very bullish for the easy money trade."
European stocks ended mildly higher on hopes that the Greek parliament will pass the legislation needed to secure a third bailout. Asian shares were mixed with Chinese stocks ending a three-day winning streak to close just over 1 percent lower.
"My guess is we're following Europe. The retail sales number was so bad that we're not reacting to it," Peter Boockvar, chief market analyst at The Lindsey Group, said of the afternoon drift higher in equities. It's a "continuation of the Greek (relief) rally."
The Greek finance ministry submitted a reform bill Tuesday. The nation's parliament has until Wednesday night to approve the legislation, paving the way for Athens to meet a Monday repayment deadline to the European Central Bank.
"If (Greece and Germany) can't get this passed by Monday then all hell could break loose again," said John Caruso, senior market strategist at RJ O'Brien & Associates.
He expects gold to decline further and prices on the 10-year Treasury note to rise towards last week's highs.
Read MoreGreece secures bailout: What next?
In other international news, Iran and six major powers early on Tuesday clinched a historic nuclear deal that will see some sanctions against Tehran eased in exchange for restrictions on its nuclear program.
U.S. crude oil settled 84 cents higher at $53.04 a barrel. Earlier, oil briefly fell more than 2 percent as investors anticipated an increase in Iran oil exports as sanctions are eased. The energy sector rose more than half a percent as the second-best sector in the S&P 500.
"I think the biggest change in sentiment is energy turning around," said Art Hogan, chief market strategist at Wunderlich Securities.
"With (Iran) as a backdrop I think we're going to focus on how companies are doing," he said earlier.