Stocks rose Tuesday, the first trading day of 2017, but came off their session highs as oil prices gave back some of their initial gains.

The S&P 500 traded 0.43 percent higher, with telecommunications leading advancers. The Nasdaq advanced 0.38 percent. The Dow gained about 41 points, with Goldman Sachs contributing the most gains.

Crude prices hit 18-month highs amid hopes that a deal struck between OPEC and non-OPEC countries to cut production will reduce excess supply. At session highs, U.S. crude prices had gained more than 2 percent. As of 11:12 a.m. ET, however, U.S. oil prices were up 0.89 percent at $54.23 per barrel.

The three major indexes traded around 1 percent higher earlier on Tuesday, with the Dow having risen 175.93 points at session highs. "The real excitement earlier this morning came on the back of global markets rallying and [strong] PMIs," said Art Hogan, chief market strategist at Wunderlich Securities, adding that strong oil prices were also boosting equities.

He also said "you really have to juxtapose the strong gains we've had [in stocks] against the strong dollar. I think that's starting to seep into the market here." The U.S. dollar rose more than 1 percent against a basket of currencies, with the euro trading near $1.041 and the yen around 117.8.

Chinese stocks closed higher on the back of strong domestic data and of crude's spike, with the Shanghai composite rising 1.04 percent. China's Caixin Manufacturing Purchasing Managers' index (PMI) rose to 51.9, compared with 50.9 in November and beating forecasts for 50.7, on the back of increased demand.

"The first couple of days of the year set the direction for the market. I don't see anything interfering here. I think enthusiasm is still there," said Peter Cardillo, chief market economist at First Standard Financial. European equities also rose, with the Stoxx 600 Europe index advancing around 0.76 percent.

"Traders likely woke up this morning a bit surprised. Most portfolio managers likely surmised that last week's sell-off marked the start of a modest pullback for the broader indices that would dominate the early part of 2017 as institutions normalize their risk and many investors clip profits in an effort to defer capital gains," said Jeremy Klein, chief market strategist at FBN Securities.

In U.S. economic news, the final read on December IHS Markit manufacturing PMI came in at 54.3, hitting a 21-month high. A number above 50 signals expansion, while a number below 50 shows contraction. The ISM manufacturing index read for December, meanwhile, came in at 54.7, above November's read of 53.2. and construction spending hit its highest level in more than 10 years in November.

"We're seeing the exact opposite of what happened last year, in terms of investing and sentiment," said Adam Sarhan, CEO at 50 Park Investments. "The macro picture is improving and the stock market is forecasting better economic data and stronger earnings. That bodes well for Main Street and Wall Street."

U.S. Treasurys fell on Tuesday, with the benchmark 10-year note yields rising to 2.485 percent and the short-term two-year note yield trading at 1.242 percent.

In corporate news, President-elect Donald Trump attacked General Motors in a tweet, claiming the auto giant is making a Chevy Cruze model in Mexico and then sending them to U.S. dealers tax free. GM later responded by saying that most of its Cruze models are in fact built in the U.S.