US stocks bobbed higher today as technology and consumer-focused companies regained a sliver of their losses from the day before.
Oil prices and energy companies jumped as the US pressed its allies to stop importing oil from Iran.
Coming off their worst loss since early April, stocks were on track for hefty gains Tuesday afternoon but weakened late in the day.
Technology companies like Apple bounced back after abrupt losses on Monday.
General Electric led industrial companies higher after it said it would shrink even further by spinning off its health care business and its oil service unit.
Banks and other financial companies took losses as bond yields and interest rates remained well off their highs from last month. Household goods makers also slipped.
Julian Emanuel, chief equity and derivative strategist for BTIG, said the stock market was going to be volatile as long as investors were concentrating on the trade disputes the US was having with many of its biggest trading partners.
"The economy is strong as it stands now and earnings are great, but when all of the psychic energy and all of the focus is on the trade war, as it was in late March and early April, the market has responded accordingly," he said.
The S&P 500 index gained 5.99 points, or 0.2%, to 2,723.06. It fell 1.4% Monday.
The Dow Jones Industrial Average gained 30.31 points, or 0.1%, to 24,283.11.
The Nasdaq composite added 29.62 points, or 0.4%, to 7,561.63 after it plunged 2.1% a day ago.
The Russell 2000 index picked up 11.02 points, or 0.7%, to 1,668.53.
A senior State Department official said the Trump administration wanted allies to stop importing oil from Iran.
If they do it would increase demand from other countries, which would likely produce more oil to pick up the slack.
Benchmark US crude added 3.6% to 70.53 dollars a barrel in New York. Brent crude, used to price international oils, rose 2.1% to 76.31 dollars per barrel in London.
Exxon Mobil jumped 1.1% to 80.64 dollars and Chevron picked up 1.3% to 124.16 dollars.
Apple climbed 1.2% to 184.43 dollars and Facebook gained 1.3% to 199 dollars.
Technology stocks were hammered Monday as investors reacted to reports that the Trump administration might bar technology companies from selling certain high-tech products to China and other countries and limit investment in tech companies by Chinese firms.
Stocks recovered some of those losses after a top US trade adviser rebutted those reports.
Consumer focused companies also rose. Amazon jumped 1.7% to 1,691.09 dollars and Netflix rose 3.9% to 399.39 dollars after they both dropped on Monday.
Homebuilder Lennar climbed 4.9% to 51.61 dollars after a strong quarterly report, and its competitors also climbed.
It has been five months since the S&P 500 and Dow last closed at record highs. The S&P 500 is down 5.2% since January 26 and the Dow has fallen 8.8%.
GE jumped 7.8% to 13.74 dollars after the company said it would sell its two-thirds stake in Baker Hughes and also divest its health care business.
The company has sold numerous major businesses in recent years including its railway locomotive division, lending unit, its appliance businesses and its stake in NBC, and on Monday GE agreed to sell its gas-engine business to Advent International for 3.25 billion dollars.
Tuesday was also the first day in 110 years that General Electric was not part of the Dow Jones Industrial Average.
Bond prices were little changed. The yield on the 10-year Treasury note remained at 2.88%. Banks continued to fall, as lower interest rates reduce the profits they make on mortgages and other types of lending.