S&P ekes out gain, Nasdaq sets fresh 12-year high; FB closes below $38

The Dow and S&P 500 closed near the flatline Tuesday as investors remained cautious ahead of the Federal Reserve's policy statement, but techs climbed to lift the Nasdaq to a fresh 12-year high.

(Read more: After-hours buzz:Amgen, Aflac, Symantec & More)

S&P 500

The Dow Jones Industrial Average slipped 1.38 points to finish at 15,520.59, dragged by Verizon and AT&T.

The S&P 500 eked out a gain of 0.63 points to close at 1,685.96. The Nasdaq rose 17.33 points to end at 3,616.47, logging its highest close in nearly 12 years.

The CBOE Volatility Index (VIX), widely considered the best gauge of fear in the market, closed unchanged above 13.

Among key S&P sectors, telecoms dragged, while techs finished higher.

Among techs, Facebook advanced more than 6 percent after the social-networking giant announced the launch of Facebook Mobile Games Publishing, a "pilot program to help small and medium-sized developers take their mobile games global." The stock has surged more than 45 percent so far this month and is trading close to its IPO price of $38 a share.

(Read more: Facebook nearing its IPO price. Here's why)

And Apple rose above $450 a share for the first time in over a month. The stock has soared nearly 14 percent so far this month and is having its best month since last February.

On the earnings front, Pfizer gained after the U.S.'s largest drugmaker posted numbers that were slightly ahead of expectations. Rival pharmaceutical company Merck topped profit expectations but showed weakness on revenue.

And BP posted earnings that missed analysts' expectations, but warned that its $20 billion oil-spill compensation fund has almost run out. Following the earnings report, CEO Bob Dudley told CNBC that class action lawsuits like the ones BP is facing in the U.S. are a "business model" that serve only to benefit attorneys. Shares declined.

Aetna posted better-than-expected quarterly results, following similar earnings beats by larger rivals UnitedHealth and WellPoint.

With quarterly results in from nearly 60 percent of the S&P 500 companies, 67 percent have beaten earnings expectations—in line with the average beat over the last four quarters. Meanwhile, about 55 percent of the companies have beaten revenue expectations, more than the 48 percent of revenue beats in the past four earnings seasons, according to the latest data from Thomson Reuters.

If all remaining companies report earnings in line with estimates, earnings will be up 4 percent from last year's second quarter.

(Read more: What earnings seasonis saying about road ahead)

Amgen, Aflac, Symantec and Take Two Interactive are among notable companies scheduled to report after the closing bell.

But trading volume is likely to be muted again as investors look ahead to the statement from Federal Reserve's policy-setting meeting. In addition, the first reading of second-quarter gross domestic product will be due Wednesday. And the closely-watched July employment report will be reported Friday.

The Fed is expected to maintain its accommodative monetary policy, but investors will be looking for hints on when the central bank might start scaling back on its monthly bond-buying program. In addition, markets will also be eager for hints for who may replace Ben Bernanke next year as Fed Chairman.

(Read more: Fed expectations: will they stay or will they slow?)

"It's a pivotal time for Fed policy, and it would be advantageous to have someone at the helm who had already gone through the analytical process of getting comfortable with the last five years of policy, rather than coming in with a completely clean slate and trying to potentially reinvent it," said Ian Lyngen, senior Treasury strategist at CRT Capital.

(Read more: Fed intrigue, not policy, has market attention)

On the economic front, single-family home prices rose 1 percent in May on a seasonally adjusted basis, according to the S&P/Case-Shiller composite index of 20 metropolitan areas. Economists polled by Reuters expected a gain of 1.5 percent. Meanwhile, consumer confidence slipped slightly to a reading of 80.3 in July from an upwardly revised 82.1 in June, according to the Conference Board. Economists surveyed by Reuters expected a reading of 81.1.

Mosaic plunged nearly 20 percent after Russia's Uralkali pulled out of a venture with its partner in Belarus, a move it expects will cause global prices to plunge by 25 percent. Uralkali and Belarus potash maker Belaruskali were partners for eight years in BPC, which accounts for 43 percent of the global potash export market. Shares of Potash and Agrium also tumbled sharply.

Community Health Systems announced it would acquire smaller Health Management Associates in a $3.9 billion deal. Shares of both company finished in the red following the news.

JPMorgan closed lower after the banking giant said it would pay a total of $410 million to settle allegations of energy market manipulation in California and the Midwest.

The Japanese yen weakened against the dollar to above the 98-level in early trade, leading the export-heavy Nikkei index to rally 1.5 percent. Meanwhile, South Korea's Kospi added 0.9 percent and the Shanghai Composite traded within sight of the 2,000 mark.

European shares rose after an upbeat German consumer confidence report. The Gfk research institute said its forward-looking consumer index hit its highest level since September 2007, thanks to an improving labor market and expectations for more robust economic growth.

—By CNBC's JeeYeon Park (Follow JeeYeon on Twitter: @JeeYeonParkCNBC)

On Tap This Week:

WEDNESDAY: MBA mortgage applications, ADP employment report, GDP, employment cost index, Chicago PMI, oil inventories, FOMC mtg announcement, farm prices, Booz Allen Hamilton investor call, Electronic Arts shareholder mtg; Earnings from Comcast, Honda, MasterCard, Hess, Humana, Sodastream, Allstate, CBS, Marriott, MetLife, Whole Foods, Dreamworks Animation, Yelp
THURSDAY: Challenger job-cut report, jobless claims, PMI manufacturing index, ISM mfg index, construction spending, natural gas inventories, Fed balance sheet/money supply, auto sales, JCPenney vs. Martha Stewart closing arguments, Michael Kors shareholder mtg, Motorola Moto X launch; Earnings from AstraZeneca, ConocoPhillips, ExxonMobil, P&G, Royal Dutch Shell, Barrick Gold, Cigna, Clorox, Time Warner Cable, AIG, Kraft Foods, LinkedIn, Leap Wireless
FRIDAY: Nonfarm payrolls, personal icome & outlays, factory orders, Congress breaks for summer, Dell shareholders mtg, Detroit bankruptcy hearing; Earnings from Chevron, Toyota, Viacom

What's Trending on CNBC.com: