Stocks close mildly lower as Greece vote looms

U.S. stocks closed mildly lower on Wednesday as investors remained anxious ahead of an impending Greek parliament vote. ( Tweet This )

"I honestly believe that's what got people a little on edge (Greek protests). Obviously there's been back and forth all day as to whether or not it will pass and Yellen did reiterate we were on pace for tightening and the impression that was given was September and here we are in July," said Michael O'Rourke of JonesTrading.

The Greek parliament faces a midnight deadline (5pm ET) to pass reforms needed to secure a bailout deal from its creditors. After defaulting on a loan to the International Monetary Fund at the beginning of July, Athens has another payment due to the European Central Bank Monday.

The major averages turned lower and briefly extended losses as news of violent anti-austerity protests erupting in Athens weighed on sentiment ahead of the vote.

However, in a sign of more optimism, the Greece ETF (GREK) closed up about 10 percent for its best day since February.

Read MoreGreece latest: Violent protests erupt in Athens

"The question should be if the country can handle the very stringent changes that are required," said Quincy Krosby, market strategist at Prudential Financial. "I think it's a market that's a little nervous of how that vote comes in."

The greenback gained about half a percent, with the euro falling below $1.10, hitting a low of $1.0928 in afternoon trade as the deadline for the Greek parliament vote approached. The yen held near 123.7 yen per dollar.

European stocks ended higher as investors remained optimistic ahead of the deadline, while Greek exchange remained closed.

Netflix closed down 2.2 percent, recovering from a plunge of more than 3 percent in the first trading day after its 7-for-1 stock split . The video streaming service posts earnings after the close.

Earlier the major averages held mildly higher, with the Nasdaq outperforming as the iShares Nasdaq Biotechnology ETF (IBB) briefly rose more than 2 percent, on track for its fifth straight day of gains. Apple rose more than 1 percent.

Read MoreReceptos stock soars on deal with Celgene

We're "practically flat," said Scott Clemons, managing director at Brown Brothers Harriman. "What I read into that is there's nothing that changes the path of monetary policy."

Federal Reserve Chair Janet Yellen said Wednesday "a decision on our part to raise rates will say, 'no, the economy doesn't stink.' We're close to where we want to be and we now think the economy can not only tolerate but needs higher rates. So there have been headwinds and we've tried to use monetary policy to overcome them."

Yellen appeared before the House Financial Services Committee to deliver remarks on the economy, the first in a two-day testimony before Congress. The following question-and-answer session focused more on political than fiscal issues.

"I think the Janet Yellen testimony is the most important item on tap today," said Maris Ogg, president at Tower Bridge Advisors. "The takeaway has got to be if she is keeping the Fed on track to raise rates this year, that means the Fed is confident the economy can take it. ... That is a long-term positive."

Read MoreGundlach at Delivering Alpha: Fed's not hiking

In prepared remarks, Yellen reiterated last Friday's statement that the central bank is on pace to raise rates this year if the economy evolves as expected. She said unemployment should decline but inflation remains below the Fed's target. Greece and China topped the list of uncertainties in Yellen's testimony.

"There really wasn't anything new and different from Yellen other than the time when she spoke," said Krishna Memani, chief investment officer at Oppenheimer Funds. "The fact that retail sales fell doesn't help the case for September."

"I think it's just a continuation of the risk-on phenomena that started last week with the Greece situation being presumably resolved and China (also)," he said.

Cleveland Fed President Loretta Mester said in prepared remarks that the central bank can start to withdraw its "emergency" policy accommodation now that the labor market is largely healed, Reuters reported.

Later in the day, Reuters reported that San Francisco Fed President John Williams said the central bank will likely begin raising short-term interest rates this year.

Wednesday's economic data was more encouraging than Tuesday's disappointing retail sales report. U.S. June producer price report showed an increase of 0.4 percent in June, while the July Empire State Survey came in at 3.9, topping June's negative 2 read.

June industrial production showed an increase of 0.3 percent, with capacity utilization at 78.4 percent, up a touch from May.

The Fed's Beige Book showed that the U.S. economy continued to expand at a moderate to modest pace through June.

It "still seems to be a moderate growth environment. Wage growth (is) improving," said Eric Lascelles, chief economist at RBC Global Asset Management. "It looks like an OK report. The prior report was a clear victory. This one looks more middling to me."

He said Tuesday's 0.3 percent decline in June retail sales would likely be moderated by a gain in July.

Treasury yields reversed initial gains to trade mostly lower, with the 2-year yield falling to 0.62 percent as traders weighed the possibility of a rate hike later this year. The 10-year yield briefly edged higher before falling to 2.35 percent, following the 10-year German bund yield lower.

"While Greece is a constant smoldering issue prone to flare up, the real driver of U.S. rates at the moment is the Fed," said Brandon Swensen, co-head of the fixed income desk at RBC Global Asset Management. "The outlook for the timing and trajectory of liftoff remains highly uncertain and Yellen reminded the market of this fact again today."

Overseas, China second-quarter GDP came in at 7 percent, beating expectations. However, the volatile mainland stocks reversed a recent recovery as the Shanghai Composite plunged 3 percent.

In Canada, the central bank cut interest rates to 0.5 percent from 0.75 percent, the second reduction this year.

Oil settled down $1.63, or 3.07 percent, at $51.41 a barrel, as federal data showed a smaller decline in crude stockpiles than an earlier industry report suggested.

Gold settled down $6.10 at $1,147.40 an ounce after hitting an eight-month low of $1,140.80 earlier in the session.

U.S. stocks posted their fourth consecutive day of gains Tuesday as earnings season began and investors eyed Greece and a slight recovery in oil prices.

"The gains that we've seen in the last few days have been from a reduction in uncertainty," said David Kelly, chief global strategist at J.P. Morgan Funds. "There isn't any big uncertainty being resolved today. Janet Yellen is going to be exactly as expected."

The Fed chair continues her testimony in a speech to the Senate Banking Committee Thursday.

Second-quarter earnings season picked up with reports from Bank of America, BlackRock, US Bancorp, Delta Air Lines and PNC Financial. After the close, Intel and Netflix post results.

"It's clear the market has been able to move beyond the Greece and China and reward good fundamentals in financial companies," said Mike Arone, chief investment strategist for the intermediary business at State Street Global Advisors.

Financials traded at highs not seen since May 2008 to lead gains in the S&P 500.

Read MoreEarly movers: BLK, BAC, PRNA, DAL, LNKD & more

"I think what could be a real surprise for the markets would be a negative earnings season but I don't see that happening," said Peter Cardillo, chief market economist at Rockwell Global Capital.

The Dow Jones Industrial Average closed down 3.41 points, or 0.02 percent, at 18,050.17, with Apple leading gains and Chevron the greatest laggard.

Read MoreApple releases surprise iPod Touch refresh

The Dow transports fell about 0.7 percent.

The S&P 500 closed down 1.54 points, or 0.07 percent, at 2,107.40, with financials leading four sectors higher and energy the greatest laggard.

The Nasdaq closed down 5.95 points, or 0.12 percent, at 5,098.94.

The CBOE Volatility Index (VIX), widely considered the best gauge of fear in the market, traded near 13.8.

About three stocks declined for every two advancers on the New York Stock Exchange, with an exchange volume of 756 million and a composite volume of about 3.2 billion in the close.

Macy's surged nearly 8 percent, Ethan Allen closed up about 1.6 percent and American Realty Properties ended up 1.7 percent after making the best ideas list at CNBC's Delivering Alpha conference.

On tap this week:

Wednesday

Earnings: Intel, Netflix, Wintrust Financial

Thursday

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

Friday

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: