Wall Street pulled off its second best day of the year Tuesday after stocks suffered two days of "endless panic," CNBC's Jim Cramer said. Investors got a whiff of optimism about trade with China and Mexico, and the market surged.

"Yesterday, the proprietary oscillator I follow hit negative 5, signaling that the market had gotten oversold, which is why I told you it was time to buy," the "Mad Money" host said. "That's the real reason we could explode higher today on some chatter from foreign officials and the Federal Reserve — the market was like a coiled spring."

The Dow Jones Industrial Average added more than 512 points, while the rallied 2.14% and the Nasdaq Composite gained 2.65%.

Still, Cramer warned viewers to not be too bullish because the environment is still volatile. The host worries that the market has a "ridiculously short memory."

Officials in Washington, D.C., on Monday "declared war" against Facebook, Alphabet and Apple over antitrust concerns, he said. Each of the tech giants saw its stock surge between 1.5% and 3.7% during Tuesday's session, helping carry the tech-heavy Nasdaq index about 194 points higher.

Each of those stocks, however, is down more than 11% in the past month.

"Suddenly the government's gotten [religious] on antitrust, at least in the tech sector, and that's not great for these colossal companies," Cramer said. "As for Apple, [the] Justice [Department] is coming after them on antitrust grounds" over the App Store, and "if the trade talks with the Chinese don't restart, I think you can expect Apple to get hit maybe with a 10% tariff on its goods that are made in China."

The tech rebound could continue on Wednesday after Salesforce reported a "fantastic" quarter after Tuesday's close, Cramer said.

Outside of tech, Federal Reserve Chair Jerome Powell's comments on Tuesday helped the banks and overall market rally, Cramer said. Powell said the central bank would monitor the trade wars and "act as appropriate to sustain the expansion."

Cramer noted that a number of analysts recommended buying Uber's stock, which is within roughly $3 of its $45 IPO price, as the ride-hailing company expands into into delivery and logistics.

Industrials gained as interest rates showed signs that the economy could be in better shape than previously thought; the semiconductor sector moved higher even though the group is slowing; and Cramer's so-called "Cloud Kings" group also showed some life, Cramer said.

"Today was a textbook example of why you should always buy stocks when the market gets clobbered," Cramer said. "Remember, good things can still happen, but don't get overconfident, because bad things can happen, too."