Updated from 4:10 p.m. EDT

Stocks staged a stunning turnaround in the final hour of trade Wednesday, shrugging off soaring oil prices and a disappointing report on orders for durable goods that had earlier dragged the markets back near their lowest evels of the year.

The Dow Jones industrial Average swung to a gain of 31.93 points, or 0.32%, to 10,117.07; the S&P 500 finished with a fractional gain at 1095.42; and the Nasdaq Composite finished down 10.83 points, or 0.58%, to 1858.26. The 10-year note was trading up 7/32 to yield 4.59%, while the dollar was higher against the yen and roughly even with the euro.

Volume stayed moderate, with more than 1.5 billion shares trading on the New York Stock Exchange, where advancers and decliners were about even. On the Nasdaq, more than 1.8 billion shares changed hands, and decliners outnumbered advancers by about 3 to 2.

The late-session bounce off Monday's lows in the Nasdaq and S&P 500 lent credence to a weekly research note published earlier by Merrill Lynch that hinted of a technical bottom forming in the market.

"Now that the market's narrow, dull trading range pattern of recent months has been widely recognized and discussed, it is likely approaching an ending," wrote Richard McCabe, chief market analyst with Merrill. "Momentum indicators are not fully oversold yet, so some additional downside testing may be required in the next week or two to further improve these indicators prior to the start of a durable new phase of advance."

Mark Arbeter, chief technical analyst with Standard & Poor's, took a more cynical view in a note published Wednesday. "The recent market action is reminiscent of a bear market," he wrote. "Positive fundamental news has been met by selling. The slide in the indices is interrupted occasionally by short-covering rallies that do not generate any follow-through. The abundance of oversold readings over the last couple of months have led to only short-term recoveries, and many stocks that were holding up technically have broken down, providing few places to hide."

The Nasdaq was weighed down by weakness in technology shares, with the Philadelphia Semiconductor Index down 0.8%, the Amex Network Index down 1.1% and the Goldman Sachs Hardware Index down 0.8%. Also, the Amex Airline Index closed down 1.3%.

Oil prices hit record highs in New York after Russia's largest oil company, Yukos, said the government had ordered a halt to exports from its Siberian production unit as part of a raging tax dispute. The benchmark U.S. crude gained $1.06, or 2.5%, to $42.90 a barrel, above the record closing level of $42.33 set June 2.

On the economic front, orders for durable goods rose in June, according to a government report, but came in lower than Wall Street expected. Orders rose 0.7%, below the consensus estimate of 1.5%, after declining for the second month in a row in May by a revised 0.9%.

In Iraq, a suicide car bomb exploded outside a police recruiting center in the city of Baqouba, killing 68 people, the deadliest attack in the country since the U.S.-led coalition transferred power to the new interim government in late June, according to the Associated Press.

With an eye on geopolitics, the Democratic National Convention begins its third day Wednesday, where Sen. John Edwards of North Carolina will accept the party's nomination for vice president and deliver a speech to the crowd in Boston. Investors on Wall Street continue to weigh the chances of success for Sen. John Kerry of Massachusetts in his bid to unseat the incumbent, President Bush, and speculate on what such a development could mean for the investment climate.

Investors trying to gauge how Kerry's progress in the polls against the incumbent might be weighing on the markets could start by looking at where the marquee players on Wall Street have placed their bets.

Data released by the Federal Election Commission earlier this month -- compiled by the Center for Responsive Politics -- show that campaign donors from the financial industry favor the president, with 61% of their total $190 million in 2004 campaign contributions going to Republicans. However, Democrats haven't exactly been left in the cold, receiving more than $74 million from the industry.

The largest contributor on Wall Street, Goldman Sachs ( GS), divides its spoils of almost $4 million evenly between the parties, as does J.P. Morgan ( JPM) (over $1.3 million), and Citigroup ( C) (over $1.8 million).

Among other firms in the top 20 in campaign donations from Wall Street, Lehman Brothers ( LEH) is the only one showing a majority of cash going in Kerry's direction, giving 59% of its contributions to the Democrats. Merrill Lynch ( MER) favors Republicans, giving them 77% of its money, as does Morgan Stanley ( MWD) at 66% and UBS ( UBS) at 62%. Also, insurance, consulting and accounting firms overwhelmingly favor Bush with their checkbooks.

Wall Street historically has been tagged with a Republican bias, favoring lower tax rates and laissez-faire policies toward government regulation and trade. While market-watchers have a long list of reasons for the market's recent doldrums, the red ink in stock prices does show a rough correlation with the president's decline in the polls to levels that previously have spelled doom for incumbents.

Still, Sheldon said to the extent that the election prospects are weighing on stocks, it is mainly connected with the uncertainty of a challenger unseating an incumbent rather than a bias toward a particular party.

"The upcoming election has definitely been a factor in the market's uncertainty over the past few months," Sheldon said.

On Wednesday, media giant Time Warner ( TWX) said second-quarter earnings fell to $777 million, or 17 cents a share, from $1.06 billion, or 24 cents a share, last year. Revenue rose to $10.88 billion from $9.92 billion last year. Analysts had been forecasting earnings of 15 cents a share on revenue of $10.4 billion. The stock closed down 26 cents, or 1.5%, to $16.65.

Boeing ( BA) said it boosted profits, beating expectations, and it raised its earnings outlook through 2005, saying that its commercial jet business will show renewed growth. The defense contractor's stock closed up 79 cents, or 1.6%, to $49.01.

Biogen-Idec ( BIIB) said second-quarter earnings were $827,000, or break-even per share, compared with earnings of $28.77 million, or 17 cents a share, last year. The most recent quarter included $173 million in charges related to the Biogen-Idec merger. Excluding that and various other items, the biotech company earned 34 cents a share, 2 cents better than forecasts. Its stock closed up $1.94, or 3.4%, to $58.45.

Comcast ( CMCSA) was higher after saying it earned $262 million, or 12 cents a share, in the second quarter compared with a loss of $22 million, or 1 cent a share, last year. Per-share earnings were 2 cents better than estimates. Revenue totaled $5.1 billion in the second quarter, up from $4.6 billion in the comparable quarter last year. The stock closed down $1.18 a share, or 4.1%, to $27.56.

Overseas markets were mixed, with London's FTSE 100 closing up 0.7% to 4356 while Germany's Xetra DAX sank 0.2% to 3807. In Asia, Japan's Nikkei closed up 1.6% to 11,204, while Hong Kong's Hang Seng rose 0.2% to 12,320.

More than 85 companies are scheduled to report quarterly results before Thursday's session, including Dow Chemical ( DOW), Northrop Grumman ( NOC) and Raytheon ( RTN).

At 8:30 a.m. EDT, the government is expected to report that growth in second-quarter labor costs slowed to 0.9%, down from 1.1% in the first quarter. Also, initial jobless claims for the week ended July 24 are expected to tick up by 1,000 to 340,000.