(AP) -- Strong gains by energy companies and retailers helped nudge each of the major U.S. stocks indexes to a record high close Thursday, erasing mild losses from the day before.
The Standard & Poor's 500 index and Nasdaq composite had previously hit new highs last Friday. The Nasdaq also notched a record close on Tuesday.
Investors welcomed some better-than-expected quarterly results from Macy's and Kohl's, which spurred gains for several other big retail chains.
Energy stocks led the rally, getting a boost from a surge in oil prices. An industry report released Thursday projected a more even balance in the supply and demand for oil this year.
"It's been such an oversupplied market for a long period of time, to get that supply-demand closer to being in balance, or to be in balance, is a huge driver," said David Chalupnik, head of equities for Nuveen Asset Management. "That should at least support the commodity price."
The Dow Jones industrial average climbed 117.86 points, or 0.6 percent, to 18,613.52. The average is now up about 0.1 percent from its last record set July 20.
The S&P 500 index added 10.30 points, or 0.5 percent, to 2,185.79. That's a gain of 0.13 percent from its previous high last Friday. The Nasdaq composite index gained 23.81 points, or 0.5 percent, to 5,228.40. It edged up 0.1 percent from its previous high.
The latest market milestones reflect investors' improved confidence in the U.S. economy of late. Strong job growth, more stable oil prices and a crop of better-than-expected company earnings have helped lift stocks in recent weeks.
Still, overall earnings for companies in the S&P 500 are expected to be down 2.2 percent for the second quarter, according to S&P Global Market Intelligence.
"We're still looking at negative earnings growth, albeit improved, and negative revenue growth," said Tim Dreiling, regional investment director for U.S. Bank's Private Client Reserve. "In order for stocks to continue to make new highs and continue to grind higher, we're going to need to see some improvement in revenues and see some improvement in earnings in the second half of 2016."
The major stock indexes got off to a strong start early Thursday, bouncing back from slight losses a day earlier.
Traders bid up oil prices in response to the International Energy Agency's latest forecast. The agency said it expects that supply and demand for oil will be more in balance the rest of this year. It also projected that global oil demand won't grow as much as it previously expected next year, citing a weaker global economy.
Benchmark U.S. crude rose $1.78, or 4.3 percent, to close at $43.49 a barrel in New York. Brent crude, used to price international oils, gained $1.99, or 4.3 percent, to close at $46.04 in London.
Several oil and gas companies got a boost from the rise in crude prices. Devon Energy added $1.74, or 4.4 percent, to $41.31, while Chesapeake Energy rose 23 cents, or 4.8 percent, to $5.03.
Retailers also posted strong gains after Macy's and Kohl's reported quarterly results that beat Wall Street's expectations despite continued competition from online outlets like Amazon.com. Macy's also said it plans to close about 100 stores next year as it tries to become more nimble in a competitive market.
Macy's rose $5.81, or 17.1 percent, to $39.81, while Kohl's jumped $6.15, or 16.2 percent, to $44.19.
Investors also bought up shares in several other retail chains. Nordtsrom gained $3.33, or 7.5 percent, to $47.56, while J.C. Penney rose 79 cents, or 8.6 percent, to $9.94. The chain is scheduled to release earnings early Friday.
The retailers' earnings fueled optimism for the government's latest monthly tally of retail sales Friday.
Not all companies had favorable quarterly results.
Hamburger chain Shake Shack slumped 6.2 percent after it said sales at older locations slowed down in the latest quarter. The stock shed $2.53 to $38.34.
The major stock indexes in Europe closed higher.
Germany's DAX gained 0.9 percent, while France's CAC 40 added 1.2 percent. Britain's FTSE 100 rose 0.7 percent.
In Asia, Hong Kong's Hang Seng index closed 0.4 percent higher, while China's Shanghai Composite slipped 0.5 percent. South Korea's KOSPI edged up 0.2 percent. Japan's stock exchange was closed for a holiday.
In other energy trading, wholesale gasoline added 6 cents to $1.36 a gallon, while heating oil rose 6 cents to $1.38 a gallon. Natural gas fell a penny to $2.55 per 1,000 cubic feet.
In metals trading, the price of gold slipped $1.80, or 0.1 percent, to $1,342.50 an ounce. Silver lost 15 cents, or 0.7 percent, to $20.02 an ounce. Copper gained 2 cents, or 0.9 percent, to $2.19 a pound.
Bond prices fell. The yield on the 10-year Treasury note rose to 1.56 percent from 1.50 late Wednesday. In currency markets, the dollar strengthened to 101.93 yen from 101.29 on Wednesday. The euro weakened to $1.1141 from $1.1175.