Updated from 4:23 p.m. EDT

Stocks erased a midday swoon and closed higher Tuesday as positive earnings from a group of blue-chip companies and falling oil helped the market stabilize. Trading was restrained by looming testimony from Fed Chairman Ben Bernanke and a torrent of tech earnings due after the bell.

The Dow Jones Industrial Average recovered from a 65-point loss and finished higher by 51.87 points, or 0.48%, to 10,799.23. The Dow had fallen briefly into negative territory for the year. The S&P 500 rose 2.37 points, or 0.19%, to 1236.86, and the Nasdaq Composite added 5.50 points, or 0.27%, to 2043.23, bouncing from a 14-month low.

"Today showed that money is out of the market on the sidelines," said James Park, managing director with Rodman & Renshaw. "The volatile, range-bound trading we saw today shows how all markets are trading independent of each other. Overall, today was a very choppy, inconsistent day with traders showing a lack of conviction."

About 1.72 billion shares changed hands on the New York Stock Exchange, with advancers narrowly outpacing decliners by a 9-to-8 margin. Volume on the Nasdaq was 2.04 billion shares, with advancers beating decliners 8 to 7.

The 10-year Treasury bond was down 17/32 in price to yield 5.13%, and the dollar rose against the yen and euro.

"We've been reversing some of the safe-haven flows we've seen recently," said John Canavan, market analyst with Stone & McCarthy Research Associates. "The situation in the Middle East hasn't escalated too much further, which is why we're seeing this change. At this point, there's also a possibility of nervous position-squaring ahead of further economic data."

The indices overcame weakness from Target ( TGT) after the retailer slashed its same-store growth forecast for July, dropping its estimate to a range of 3% to 4%. Target had originally predicted growth in a range of 4% to 6%. Shares slid $2.02, or 4.3%, to close at $45.53.

Another headwind was the producer price index, which rose 0.5% in June, slightly above forecasts. The core number, which excludes food and energy, rose 0.2%, in line with expectations. The core PPI number is now up 1.9% year over year, the highest since September.

To view Gregg Greenberg's video take on today's market, click here .

The government will release the consumer price index, which is more closely watched for inflationary pressure, on Wednesday. Cardillo says that "while the CPI is more important right now, we're looking for anything that will help." Also Wednesday, Bernanke will begin two days of testimony on Capitol Hill. The semiannual report on banking, housing and urban affairs will begin before the Senate and conclude Thursday before the House.

Elsewhere, oil fell for a second day even as Israel pressed its military offensive against Lebanon for a seventh day. As many as 26 people were killed in Israeli bombing raids Tuesday, according to reports, while more than 100,000 Lebanese are said to have fled their homes to avoid the fighting. At the U.N., Secretary General Kofi Annan called for the deployment of an international peacekeeping force, although Israel opposes such a move.

Crude finished the session down $1.76 to $73.54 a barrel. Meanwhile, gold dropped $22.40 to close at $629.50 an ounce.

"The market stills remains hostage to geopolitical news," said Peter Cardillo, chief market strategist with S.W. Bach & Co. "I suspect any good numbers out of economic data may help to stabilize the market, so hopefully good inflation and earnings numbers will help keep us from falling out of a trading range."

Among the flood of quarterly earnings reports, Johnson & Johnson ( JNJ) posted second-quarter earnings of $2.82 billion, or 95 cents a share, up from $2.59 billion, or 86 cents a share, a year earlier. Excluding charges, J&J had earnings of 98 cents a share, beating the Thomson First Call consensus by a penny. The stock gave up 31 cents, or 0.5%, to $60.60.

Fellow Dow component Coca-Cola's ( KO) second-quarter earnings rose 7% from last year to $1.84 billion, or 78 cents a share. Adjusted earnings of 74 cents a share were 2 cents ahead of estimates, and sales also topped forecasts. Coca-Cola rose 85 cents, or 2%, to $43.55.

Major U.S. averages closed little changed Monday, ending a three-day streak of heavy losses. For the session, the Dow gained 8 points to 10,747, and the Nasdaq rose fractionally to 2038.

By sector, the S&P Retail Index dropped 2%, the Philadelphia Housing Sector Index was off 1.3%, and the Philadelphia Semiconductor Sector Index ended down 0.4%. The Amex Oil Index was one of few winners, finishing higher by 0.6% despite crude's sharp decline.

Returning to the earnings front, Merrill Lynch ( MER) posted a second-quarter profit of $1.6 billion, or $1.63 a share, up from $1.14 billion, or $1.14 a share, last year. Revenue jumped 29% to $8.2 billion from a year ago. Results beat the Thomson First Call consensus for EPS of $1.52 on revenue of $7.53 billion. Shares lost 77 cents, or 1.1%, to $67.50.

Second-quarter net jumped 14% at United Technologies ( UTX) to $1.1 billion, or $1.09 a share. The profit included a 7-cent restructuring charge and was well ahead of First Call estimates. United Technologies tacked on 92 cents, or 1.6%, to $58.88.

After the bell, IBM ( IBM) said second-quarter earnings rose 10.5% from a year ago to $2.02 billion, or $1.30 a share, beating estimates by a penny. Sales fell 2% to $21.9 billion, about $120 million better than the Thomson First Call forecast. During Tuesday's session, IBM rose 56 cents, or 0.8%, to $74.26.

Also after the closing bell, Yahoo! ( YHOO) said second-quarter earnings fell sharply from a year ago but still matched Wall Street forecasts. The Internet company earned $164 million, or 11 cents a share, in the latest quarter, down from a gain-swollen $755 million, or 51 cents a share, last year. Sales were $1.12 billion, excluding traffic acquisition costs, missing estimates. The stock closed up 40 cents, or 1.3%, to $32.24 then fell 7% after hours.

Among ratings moves, Goldman Sachs upgraded restaurant chains McDonald's ( MCD) and Yum! Brands ( YUM) to buy from neutral. The firm assigned stock price targets of $41 and $57, respectively. McDonald's gained 0.3% to $34.81, while Yum! finished lower by 1.1% to $47.60.

AG Edwards downgraded a handful of retailers Tuesday. The firm dropped Best Buy ( BBY), Target, JC Penney ( JCP) and Abercrombie & Fitch ( ANF) to hold from buy.

Overseas markets were lower, with London's FTSE 100 down 0.3% to 5682 and Germany's Xetra DAX off 0.4% at 5397. In Asia, Japan's Nikkei fell 2.8% to 14,437, and Hong Kong's Hang Seng lost 0.1% to 16,044.