Stocks closed at a record high Monday behind gains for chemical and machinery companies. Energy companies rose as the price of oil continued its recent recovery.

Makers of chemicals and mining companies made the biggest gains, and machinery companies and banks followed.

Investors sold government bonds and utility and phone companies. Those stocks climbed earlier in the year as investors sought safety.

Stocks have seesawed between small gains and losses for more than a week as investors consider mixed reports on the health of the economy and a decline in corporate earnings. That hasn’t stopped them from setting records, but it’s kept investors wary.

“The market has run up in anticipation of better earnings ahead,” said Brian Nick, chief investment strategist for TIAA Investments. “If those earnings don’t come, we have the Wile E. Coyote moment where we’re off the cliff...and we’re gonna fall.”

The Dow Jones industrial average climbed 59.58 points or 0.3 percent, to 18,636.05. The Standard & Poor’s 500 index rose 6.10 points, or 0.3 percent, to 2,190.15. The Nasdaq composite added 29.12 points, or 0.6 percent, to 5,262.02.

Second-quarter earnings are nearly all in the books, with this week’s releases from retailers Home Depot, Wal-Mart and Target among the last to appear. Corporate earnings are down once again this quarter and investors don’t expect much growth in the third quarter either, but they are starting to expect improvement after that.

advertisement | advertise on newsday

U.S. crude jumped $1.25, or 2.8 percent, to $45.74 a barrel in New York. Brent crude, a benchmark used to price international oils, rose $1.38, or 2.9 percent, to $48.35 a barrel in London. After a steep slide for most of June and July, the price of U.S. crude gained 6.4 percent last week.