Chip stocks have made sharp gains this year, even though analysts expect the industry's earnings to be down 20% for the first quarter and continue to decline this year, according to Refinitiv data.

The S&P technology sector closed at a record high Monday, and is up about 33% since the market's Christmas Eve sell-off. Within that sector, semiconductors have been outperforming. The SMH VanEck Vectors Semiconductor ETF is about 3% off its all-time high and very close to its 52-week high. It was trading down 1% Tuesday, but still up nearly 28% year to date.

On Tuesday, chip stocks were being sold in a broader market decline, that saw some other tech names, like Apple and Facebook hold onto gains.

Semiconductor stocks, up sharply this year on hopes for a China trade deal, could face their day of reckoning during earnings season.

"They certainly have ground to give up, and that's what gets dangerous. When you come into the earnings season with the kind of momentum we've seen in some of these high-flying names ... whether it's Nvidia or Micron ... unfortunately you're on a knife's edge and there's a potential for a great deal of volatility," said Art Hogan, chief market strategist at National Securities.

Analysts say there is a good chance that some chip companies could offer even weaker forward guidance, with demand expected to decline for everything from PCs to smartphones and cars.

"I think there's some earnings caution building in here," said Art Cashin, UBS director of floor operations at the New York Stock Exchange. But he also said there were doubts circulating about a Chinese trade deal Tuesday, after reports that President Donald Trump could put tariffs on Europe.

But despite Tuesday's sell-off, the chip stocks have been rising on the view that a turnaround could come in the second half of the year.

"Investors have discounted the entire recovery in the back half of they year," said Dan Niles, founding partner of AlphaOne Capital Partners. "Memory prices continue to go lower and PC demand looks like it will be negative this year. ... It's very hard to see these stocks sitting at all-time record highs and knowing earnings are going to be down 25%, and we've got summer sitting between now and the end of the year. If you were sitting in August and September, you could say people are getting jacked up for holiday sales."

Chip companies are expected to see earnings drop by 16.5%, then another 20.8% in the second quarter and an 18.4% decline in the third quarter, according to Refinitiv. The semiconductor equipment companies are expected to see earnings decline 36.4% for the first quarter, and the same type of drop is expected in the second quarter, according to Refinitiv data. By the fourth quarter, earnings comparisons are expected to fall by just about 4%.

"If companies come out and are cutting their forecast, do the stocks go down? The reaction to earnings will be very telling," said Niles.

Nvidia fell 1.4% Tuesday. Micron, down just 1% on Monday when Cowen downgraded it, was down 2.4% Tuesday. It has been downgraded by a number of analysts.

Oppenheimer analysts, in a note, said semiconductor shares remain sharply higher despite the "raft of estimate cuts" year to date. "We attribute much of the move to hopes for a U.S./China trade deal and 2H fundamental inflection. Near-term visibility remains poor and 2Q expectations appear low, in our view. We remain stock selective." The Oppenheimer analysts said their top picks are Broadcom, Nvidia, Marvell Technology and Monolithic Power Systems.

U.S. and Chinese negotiators continue to work on a deal that markets expect would end many of the punitive tariffs put on goods from both countries and despite the selling, there was still a sense a deal could be announced this quarter.

"People are saying it's China, China, China. ... At a certain point, we'll find out. It could be sell the news. That doesn't fix the issues. That doesn't fix the issues with global growth. A China deal is not going to make people run out and buy a 5G cellphone," said Niles.

Source: Refninitiv

Niles said the decline in smartphone sales is a big issue for chips, since 25% of chip demand is the smartphone market. He said consumers are waiting for new 5G models. "This year smartphones are going to be down more than they were last year," he said.

Another 10% of chips go into personal computers, which have been in decline since 2012, and 15% go into cloud infrastructure. "Cloud vendors are all absorbing huge spending they had last year. That's going to grow, but it's going to slow down from last year," he said.

Automobiles are about 15% of end demand, and Niles notes China had its first decline in unit sales ever last year and auto sales are expected to drop again this year.

"When you're saying most companies are going to come out and report and guide lower, the positives are obviously investors are saying the Fed's done and we're going to get a trade deal with China and that's going to fix everything. I would say not really, the economy was slowing down globally already," said Niles.