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.
Second-quarter earnings season kicked off with banks JPMorgan Chase and Wells Fargo and pharmaceutical firm Johnson & Johnson reporting before the opening bell. CSX and Yum Brands report after the close.
JPMorgan Chase gained 1.4 percent after delivering quarterly earnings that topped analysts' expectations on Tuesday, helped by lower expenses. Revenue beat expectations slightly but was lower year-over-year.
Johnson & Johnson fell 0.49 percent as the greatest laggard in the Dow after the firm in quarterly profit as sales of its mainstay older drugs managed to offset the impact of a strong dollar on overseas revenue.
Wells Fargo gained 0.9 percent after posting earnings per share in-line with estimates on revenue slightly below expectations.
The bank earnings are "probably an indication that earnings season is going to be tepid as well," said Jack Ablin, chief investment officer at BMO Private Bank.
However, other analysts were more optimistic.
"I believe this earnings season there's going to be some positive surprises," said Bob Baur, chief global economist at Principal Global Investors. "We're just getting rid of some of the volatility on Greece and focusing on what's happening in the U.S."
Stock index futures were narrowly mixed in early trade, with S&P and Dow futures extending losses slightly after retail sales showed a decline of 0.3 percent, missing expectations of a 0.3 percent increase.
In other economic news, May , in-line with expectations. Business sales rose 0.4 percent after increasing 0.5 percent in April.
U.S. import prices unexpectedly fell in June as the lingering effects of a strong dollar offset rising costs for petroleum products, keeping imported inflation pressure under wraps.
Treasury yields held lower, with the 10-year yield at 2.40 percent after dipping below 2.4 percent on retail sales. The dollar fell against world currencies, with the euro above $1.10 and the yen at 123 yen against the greenback.
"I think to some extent the focus on the overseas problem (has) allowed us to ignore that we have a growth problem in the U.S.," said Bruce McCain, chief investment strategist at Key Private Bank. "Especially if you get disappointment in things like retail sales, that's going to underscore that trend."
Earlier, U.S. small business confidence fell in June to its lowest level in more than a year amid expectations of weaker profits and a softening labor market, which could temper expectations for strong economic growth in the second half.
"To a certain extent, bad news keeps the Fed at bay," said Ben Pace, chief investment officer at HPM Partners. "Maybe the thought is the Fed might delay (a rate hike)."
Kansas City Fed President Esther George speaks at 8:15 p.m. ET Tuesday on economic conditions and monetary policy.
In individual stock news, Netflix dipped more than 1 percent ahead of its 7-for-1 stock split after the close. The media company also posts earnings after the close Wednesday.
The closed up 9.36 points, or 0.45 percent, at 2,108.96, with health care leading nine sectors higher and utilities the only laggard.
The Nasdaq closed up 33.38 points, or 0.66 percent, at 5,104.89
The CBOE Volatility Index (VIX), widely considered the best gauge of fear in the market, dipped below 13.
"I'm frankly amazed at how quickly it's come back down," said Randy Frederick, managing director of trading and derivatives at Charles Schwab. "I would guess the VIX has overreacted to the downside."
About two stocks advanced for every decliner on the New York Stock Exchange, with an exchange volume of 694 million and a composite volume of nearly 3 billion, below the average 3.4 billion.
Gold futures ended down $1.90 at $1,153.50 an ounce.
—Reuters contributed to this report.
On tap this week:
Earnings: CSX, Yum Brands
8:15 p.m.: Kansas City Fed President Esther George
CNBC's Delivering Alpha conference
Earnings: Bank of America, BlackRock, US Bancorp, Delta Air Lines, PNC Financial, Intel, Netflix, ASML Holding, Wintrust Financial
8:30 a.m.: PPI
8:30 a.m.: Empire State survey
9:15 a.m.: Industrial production
10:00 a.m.: Fed Chair Janet Yellen semiannual testimony before House Financial Services
12:25 p.m.: Cleveland Fed President Loretta Mester on economic outlook
2:00 p.m.: Beige book
3:00 p.m.: San Francisco Fed President John Williams on outlook
Earnings: Citigroup, Goldman Sachs, Google, Sclumberger, Advanced Micro, Philip Morris, UnitedHealth, Blackstone, Charles Schwab, KeyCorp, Sherwin-Williams, Taiwan Semiconductor, Domino's Pizza, Mattel
8:30 a.m.: Initial claims
10:00 a.m.: Philadelphia Fed survey
10:00 a.m.: NAHB survey
2:30 p.m.: Fed Chair Yellen semiannual testimony before Senate Banking Committee
4:00 p.m.: TIC data
Earnings: General Electric, Honeywell, Kansas City Southern, JB Hunt, Synchrony Financial, WW Grainger
8:30 a.m.: CPI
8:30 a.m.: Housing starts
10:00 a.m.: Consumer sentiment
More From CNBC.com: