Stocks closed pretty flat Wednesday as investors deciphered messages on a potential U.S.-China trade deal from President Trump and Treasury Secretary Steven Mnuchin ahead of this weekend’s Group of 20 summit.

The Dow Jones industrial average and Standard & Poor’s 500 index finished in a neutral position after making gains during the day. The tech-heavy Nasdaq Composite closed with a small gain on good news in the semiconductor sector.

“The market is sensing some kind of agreement is going to come out of the G-20, despite the president’s posturing,” said Jeffrey Saut of Capital Wealth Planning.

Ahead of his upcoming meeting with Chinese leader Xi Jinping at the G-20 summit in Osaka, Japan, Trump said that Beijing wants to make a deal more than the United States, and that he is “very happy” with where negotiations are now. But in a wide-ranging Fox Business interview, Trump also said he would be willing to go through with the tariffs on the remaining $300 billion in Chinese goods if a deal wasn’t reached, adding that the penalties could be 10 percent instead of the proposed 25 percent, which “people could absolutely handle.”

If no deal is reached, “My plan B with China is to take in billions and billions of dollars a month and we’ll do less and less business with them,” he said.

The president’s comments came after Mnuchin told CNBC he was hopeful the upcoming meeting between Trump and Xi would kick-start stalled trade talks. Though the treasury chief declined to speculate on whether a trade deal would be reached by year’s end, he estimated the two nations were “about 90 percent of the way” there.

“I think there’s a path to complete this,” Mnuchin said.

The Dow Jones industrial average surged more than 100 points in afternoon trading before closing the day at 26,536, an 11-point loss. The blue-chip index had rebounded from a 179-point loss on Tuesday and still remains on track for its strongest June in 64 years. The 30-stock Dow is less than 200 points, or 0.75 percent, from its record close of 26,828, on Oct. 3, 2018.

The broad Standard & Poor’s 500 fell for the fourth straight day, dropping 3.6 points to close at 2,913, down about 0.12 percent. The index struck a high at its close last Thursday but has since retreated. It is less than 1 percent off that record close.

“The prospects of some progress at the G-20 have picked up,” said Howard Silverblatt of S&P Dow Jones Indices. “While the news is good now, the volatility of that last week demonstrates how that market is one tweet away from a directional change.”

Energy stocks, including ConocoPhillips and Hess, were the big drivers, with the S&P 500 energy sector surging 1.87 percent after the U.S. Energy Information Agency reported a large drawdown on oil inventories in the last week. Oil prices have rebounded the last two weeks over Trump’s added sanctions on Iran and general Mideast tensions. U.S. crude oil has jumped $8 per barrel in the past week, reaching its highest level since May 30. The increase is likely to make its way to higher pump prices in July.

Information technology, the largest sector in the S&P 500, was up 1.19 percent, led by Micron Technology, up 13 percent on its best day ever. Also performing well were Western Digital, up 7.3 percent, and Chinese e-commerce company JD.com, up 5.75 percent. Those stocks helped the Nasdaq break a three-session loss, finishing up 25 points at 7,909. The tech-laden Nasdaq is still 3 percent off its all-time high.

Ed Yardeni of Yardeni Research attributed Wednesday’s stock surge to Micron’s better-than-average earnings, which helped boost semiconductor stocks and then spread across markets.

“There had been widespread fears Micron would disappoint, reflecting slower global economic activity and the growing trade war with China,” Yardeni said. “That was not the case. So happy days are here again.”

Six out of 11 S&P sectors finished in positive territory, with energy, information and technology leading the way. The big drags were utilities and real estate, both historical safe havens. Investors showed some renewed appetite for riskier assets as they gauge U.S.-China trade talks as events unfold in Japan over the next few days.

“Positioning ahead of the G-20 summit meeting between Trump and Xi could see investors want skin in the game ahead of what many feel could yield a very positive outcome,” Ed Moya, an analyst with OANDA, wrote in a note to investors Wednesday. “A reset of talks is likely becoming the base case scenario and if we see a timeline put in place, we could see equities resume the march toward uncharted territory.”

Trump and Xi’s meeting in Osaka will be their first face-to-face encounter since late 2018, at the G-20 meeting in Argentina, where they agreed to pursue a trade deal. At one point in May, negotiations were “95 percent complete,” by Trump’s estimation, but talks frayed and froze after the United States accused China of going back on prior commitments.

But on CNBC, Mnuchin said that Trump and Xi have a “very close working relationship” and that he was hopeful for a fair outcome for both nations.

“The message we want to hear is that they want to come back to the table and continue because I think there is a good outcome for their economy and the U.S. economy to get balanced trade and to continue to build on this relationship.” he said.

The stalled trade talks gave way to escalating tariffs between China and the U.S., prompting fears of a global slowdown as two of the world’s most powerful economic engines were stalled by trade conflict. In a G-20 briefing note, Christine Lagarde, managing director of the International Monetary Fund, warned that the last round of proposed tariffs against China could erase $455 billion in global gross domestic product in 2020.

“There is strong evidence that the United States, China and the world economy are the losers from the current trade tensions,” she wrote.

The formidable head winds from the trade war have challenged the Federal Reserve as it tries to evaluate the need for a possible rate cut. Although meetings last week concluded without an announcement of a cut, the central bank foreshadowed a rate cut in July to stabilize the economy amid trade tensions, spurring investor confidence and lifting markets. But yesterday, Federal Reserve Board Chair Jerome H. Powell said the central bank was still grappling with whether to move forward with a cut.

“The Fed is insulated from short-term political pressures — what is often referred to as our 'independence,” Powell said at a Council on Foreign Relations event in New York. “The question my colleagues and I am grappling with is whether these uncertainties will continue to weigh on the outlook and thus call for additional policy accommodation.”

Trump renewed his attacks on Powell in the Fox Business interview, slamming the Fed chair for not lowering interest rates to help the United States compete with other countries. He criticized Powell for “trying to prove how tough he is” and said he “has the right to fire” Powell, though Trump did not specify whether he intends to follow through.

Trump added that the Fed should have Mario Draghi, president of the European Central Bank, as a leader “instead of our Fed person,” despite having attacked Draghi in tweets earlier this month, accusing him of currency manipulation.