Stocks rose on Wednesday, but gave up most of their gains heading into the close even after the U.S. and China signed a highly anticipated phase one trade agreement.

Most of the details were already known and investors anticipated some speed bumps on the way to phase two's signing.

The Nasdaq Composite closed just above the flatline at 9,258.70. The S&P 500 ended the day up 0.2% at 3,289.29 while the the Dow Jones Industrial Average gained 90.55 points, or 0.3% to close at 29,030.22. At its session high, the Dow was up 187.92 points, or 0.7% while the S&P 500 and Nasdaq gained as much as 0.5% each.

The U.S.-China trade agreement includes provisions to curb intellectual property theft along with forced technology transfers. It also increases Chinese purchases of U.S. products. Investors had been eagerly awaiting the signing of the so-called phase one trade agreement as the conflict between the world's largest economies has dragged on for nearly two years.

"The risk in the market is that the trade situation deteriorates, not that it stays the way it is," said Willie Delwiche, investment strategist at Baird. "If it's improving, then by definition it's not deteriorating and that's a good thing."

To be sure, the deal does not remove existing U.S. tariffs on Chinese imports and leaves questions as to how the terms of the agreement will be enforced. The deal is also seen as "fragile" by some analysts who believe additional levies could still be implemented.