U.S. stocks closed higher Wednesday, helped by a recovery in health care stocks and gains in energy, as investors awaited the beginning of earnings season. (Tweet This)
Health care was the greatest advancer in the S&P 500 on the day, helping the index come within 5 points of the psychologically key 2,000 level.
The index also found support from gains of about 1.3 percent in materials, industrials and energy.
"Oil prices are what were supporting the surge. We'll need to see better earnings, higher revenues in order to support this," said Chris Gaffney, president of world markets at Everbank.
After rising nearly 1 percent in opening trade, the major averages briefly dipped into negative territory, following declines in oil prices.
"I think what happened here was people said this was a good place to take profits," said Marc Chaikin, CEO of Chaikin Analytics. He doesn't think stocks have bottomed yet and noted that the S&P 500 hit resistance between 1,980 and 2,000.
"There's going to be a sort of a battleground right there," he said. "A lot of people piled into the market (in the last few days) especially in energy and materials, because they thought a W-bottom had occurred."
Oil fluctuated between gains and losses after weekly oil inventories showed an increase of 3.073 million barrels, above expectations of an increase of 2.5 million barrels.
Crude settled down 72 cents, or 1.48 percent, at $47.81 a barrel, giving back some of Tuesday's 4.9 percent surge. Brent held just above $51 a barrel.
"If you look at the positive influence on the market this week and last week, it's been commodities," said Art Hogan, chief market strategist at Wunderlich Securities.
Crude has not closed outside of a $5.20 range between $44 and $49.20 a barrel since Aug. 27.
"I think oil's put in a nice bottom here," said Peter Coleman, head of trading at Convergex. "People are looking at bottom fishing into the energy sector at this point. ... The money coming out of biotech and health care in general is making it back into the energy sector."
He added that the market held up pretty well Tuesday despite a sharp drop in the biotech sector. "There's a bit of a bias to buy at this point," Coleman said ahead of the opening bell.
Stocks closed mixed Tuesday with the Dow up about 14 points and the S&P down 7 points, or 0.36 percent. All three major averages are within 10 percent of their 52-week highs, or out of correction territory. The Nasdaq composite is the only major index positive for 2015.
"Overall it seems like we're sort of bouncing around here after the last major update from the Fed," said Mike Bailey, director of research and chair of FBB Capital Partners. "Folks are waiting for earnings season."
YUM Brands plunged 18.8 percent after reporting earnings late Tuesday that missed expectations. The fast food company also disappointed in its key China division with much weaker-than-expected growth in same-store sales.
In other corporate news, SABMiller said it rejected Anheuser-Busch InBev's raised bid, which would have given it a value of nearly £68 billion ($103.6 billion).
European stocks pared gains to close mildly higher on Wednesday, with auto stocks and miners outperforming after some recovery in oil prices.
Advances in energy also helped Asian stocks close higher, with the Nikkei up 0.75 percent and the Hang Seng leaping 3.13 percent.
In a light day of economic releases, the Mortgage Bankers Association said early Wednesday that weekly mortgage applications rose 25.5 percent amid anxiety over new mortgage regulations.
August consumer credit increased to $16.02 billion, while July consumer credit was revised up to $18.94 billion from $19.10 billion, Dow Jones reported.
Treasury Department auctioned $21 billion of 10-year notes at a high yield of 2.066 percent.
Treasury yields held higher, with the 10-year yield at 2.07 percent and the at 0.62 percent.
The U.S. dollar held a touch higher against major world currencies, with the euro near $1.12 and the yen at 119.9 yen against the dollar.
In commodities markets, copper pared gains to trade about half a percent higher.
Dane Davis, commodities research analyst at Barclays, said price support came from announced cuts to supply and forecasts that the market could fall into deficit.
"I think there's been a real change in sentiment," he said, noting that in the long term, Barclays expects weak demand to weigh on any gains in prices from production cut news.
The late on Tuesday that it expects the global copper market will see a deficit of 130,000 tonnes in 2016, reversing its prior estimate of a 230,000-tonne surplus.
The closed up 15.91 points, or 0.80 percent, at 1,995.83, with health care leading eight sectors higher and utilities and telecommunications the only decliners.
The Nasdaq closed up 42.79 points, or 0.90 percent, at 4,791.15.
The CBOE Volatility Index (VIX), widely considered the best gauge of fear in the market, traded near 18.5.
About four stocks advanced for every decliner on the New York Stock Exchange, with an exchange volume of 1.2 billion and a composite volume of 4.6 billion in the close.
Gold futures settled up $2.30 at $1,148.70 an ounce.
On tap this week:
3 p.m.: Consumer credit
Earnings: Alcoa, Domino's Pizza, Ruby Tuesday
8:30 a.m.: Initial claims
9:30 a.m.: St. Louis Fed President James Bullard speaks
10:30 a.m.: Natural Gas Inventories
1 p.m.: 30-year note auction
1 p.m.: Minneapolis Fed President Narayana Kocherlakota speaks
2 p.m.: FOMC minutes
3:30 p.m.: San Francisco Federal Reserve Bank President John Williams speaks
4:30 p.m.: Fed Balance Sheet/Money Supply
8:30 a.m.: Import prices
10 a.m.: Wholesale trade
11 a.m.: New York Fed President's William Dudley speaks
1 p.m.: Baker-Hughes Rig Count
1:30 p.m.: Chicago Fed President's Charles Evans speaks
More From CNBC.com: