U.S. stocks closed mildly higher on Tuesday as investors remained optimistic on the Greece debt talks and eyed continued signs of moderate economic growth. (Tweet This)
"We had some generally positive factors supporting the markets today," said Ben Garber, capital markets economist at Moody's Analytics. "More optimism related to Greece. Positive economic data—core durable goods (rose) and a jump in new home sales."
The Nasdaq Composite closed a record for the second day in a row. The index touched a fresh intraday high soon after the open but traded below the flatline for much of the day. The Dow Jones industrial average and S&P 500 also approached closing highs after fluctuating in midday trade.
After some recent weakness, the U.S. dollar rose on Tuesday amid the economic reports and gains in Treasury yields.
"Today's biggest news was the strength in the dollar. That's probably the single biggest thing that's taken the rally and turned it negative," said James Meyer, chief investment officer at Tower Bridge Advisors.
The dollar rose more than 1 percent against major world currencies. The euro fell to trade below $1.12, while the yen weakened to about 124 yen against the dollar.
Investors also watched higher bond yields, which pressured utilities to fall more than 1 percent as the greatest laggard in the S&P 500.
"Considering the strength of the dollar and the rise in the yields this morning the strength of the (equity) markets is impressive," said Peter Cardillo, chief market economist at Rockwell Global Capital.
Treasury yields pared gains slightly, with the 10-year yield near 2.41 percent, off a session high of 2.42 percent. The held near 0.67 percent after the U.S. Treasury auctioned $26 billion 2-year notes at a high yield of 0.692 percent.
Read More Bond bears back on hopes of Greece deal
The morning's data releases continued to show moderate economic growth, with a greater-than-expected decline in the headline durable goods figure balancing out the best new home sales report since February 2008.
"Bad news isn't good news anymore. Bad news is ok news," said JJ Kinahan, chief strategist at TD Ameritrade. He added that if the S&P 500 fails to break past its record high of 2,130, the index could fall back down to near 2,070, the lower end of its recent trading range.
The Russell 2000 extended gains to hit a new high after also closing at a record on Monday.
"The small caps tend to be a good gauge for the risk-on trade," said Adam Sarhan, CEO of Sarhan Capital. It "supports the notion that more investors are looking to buy stocks."
European stocks closed higher on anticipation of resolution in the Greece debt crisis. Overnight, Japan's blue-chip Nikkei index also hit a 15-year high.
Greece's State Minister Nikos Pappas said on Tuesday in a Reuters report he was confident parliament would back a deal the crisis-hit country hopes to strike with its lenders even though dissenters have criticized concessions offered by Greece.
Separately, Reuters reported that Athens negotiator Euclid Tsakalotos said he believes they are closer to a deal than ever. When asked about the June 30 payment deadline to the International Monetary Fund, he said the deal will enable them to fulfill obligations.
The anti-austerity Greek government presented new budget proposals on Monday, raising hopes that Athens will be able to secure a cash-for-reforms deal with its international creditors. A Greek default and exit form the euro zone could potentially have a negative effect on global markets.
The European Central Bank on Tuesday lifted the ceiling on emergency liquidity to Greek banks for a second time in two days, said Reuters, citing a banking source.
"I do believe Greece and news there in Europe is dictating today," said Nick Raich, CEO of The Earnings Scout. "Make no mistake, if we don't get another 'kick the can down the road' Greece is on the brink of disaster."
In the United States, any further signs that the economic recovery is picking up pace after a tepid first quarter could reinforce expectations for a September rise in U.S. interest rates. Data on Monday showed existing home sales jumped 5.1 percent in May to a 5-1/2 year high. Tuesday's reports continued to indicate strength in the housing market but more moderate growth in the rest of the economy.
The FHFA Housing Price Index showed an increase of 0.3 percent in April. rose 2.2 percent in May to a more than seven-year high. In another encouraging sign, the Richmond manufacturing index rose to 6 in June, up from 1 in May.
U.S. durable goods data for May showed a decline of 1.8 percent, a greater decline than expected. The core figure of non-defense capital goods orders excluding aircraft rose 0.4 percent, reversing a 0.3 percent decline in April.
"This is an economic recovery but very mixed and fragile," Raich said. "We're seeing that growth is going to pick up in the second quarter but not nearly as much as (the second quarter last year). The durable goods number for me continues to reinforce that."
Growth in the U.S. manufacturing sector moderated in June for a third month in a row, slipping to its slowest pace since late 2013, according to Markit's preliminary U.S. Manufacturing Purchasing Managers' Index.
Federal Reserve Board Governor Jerome Powell said at a Wall Street Journal breakfast that he sees conditions for liftoff as soon as September, followed by a second hike in December, Dow Jones reported. He also said he sees growth around 2 percent this year, with positive signs from the pickup in wages and labor force participation.
The closed up 1.35 points, or 0.06 percent, at 2,124.20, with utilities leading five sectors lower and telecommunications the greatest gainer.
The Nasdaq closed up 6.12 points, or 0.12 percent, at 5,160.09.
The CBOE Volatility Index (VIX), widely considered the best gauge of fear in the market, traded near 12.
About three stocks advanced for every two decliners on the New York Stock Exchange, with an exchange volume of 690 million and a composite volume of 3.0 billion in the close.
Crude oil futures for August delivery settled up 63 cents, or 1.00 percent, at $61.01 a barrel on the New York Mercantile Exchange. Gold futures ended $7.50 lower at $1,176.60 an ounce.
In corporate news:
BlackBerry fell 4.2 percent after the handset maker missed estimates on both the top and bottom lines. However, the firm's tech and software licensing revenue jumped from a year earlier and its adjusted profit margins were also above expectations.
Darden Restaurants closed 0.01 percent higher—or flat. The Olive Garden parent reported adjusted quarterly profit of $1.08 per share, 15 cents above estimates, with revenue also beating. Darden also said it would pursue a spin-off of its real estate assets into a REIT, followed by a leaseback of the properties involved.
AT&T jumped nearly 2.5 percent after the stock was upgraded to "overweight" from "neutral" at Barclays, which cited the potential positive effects of AT&T's purchase of DirecTV.
—CNBC's Peter Schacknow contributed to this report.
On tap this week:
8:30 am: Real Q1 GDP (3rd)
1:00 pm: Five-year auction
8:00 am: Fed Gov. Daniel Tarullo on economy and financial regulation
8:30 am: Initial claims
8:30 am: Personal income/spending
9:45 am: Services PMI
9:45 am: Fed Gov. Jerome Powell on payment system
1:00 pm: 7-year note auction
10:00 am: Consumer sentiment
12:45 pm: Kansas City Fed President Esther George on the payments system
More From CNBC.com: