Stocks had their best January gains in more than 30 years, and that should mean 2019 will be a pretty good year for the market.

That's what the widely watched January barometer tells you — as goes January, so goes the year. According to Stock Trader's Almanac, going back to 1950, that metric of January's performance predicting the year has worked 87 percent of the time with only nine major errors, through 2017. In the years January was positive, going back to 1945, the market ended higher 83 percent of the time, according to CFRA.

But the indicator also signaled a positive year last year, and the market suffered an unusual late-year sell-off, wiping out all of the gains. The ended 2018 down 6.6 percent, despite rising 5.6 percent in January. But the S&P also defied history with a terrible December decline of 9.6 percent, the biggest loss for the final month of the year since 1931.

This January, the S&P 500 was up 7.9 percent. The best January performance since 1987, when it rose 13.2 percent. It was its best overall month since October 2015.

Some market pros worry the sharp snapback in stocks since the late December low means January could be stealing the gains from the rest of the year. Some also believe there could be another test at lower levels in the not too distant future. Yet, Wall Street forecasters have a median target of 2,950 for the S&P 500 at year end, a big leap from the current 2,704.

"I'm still struck between the contrast of a year ago and now," said James Paulsen, chief investment strategist at Leuthhold Group. "We came in last year with nothing but optimism. At this point last year, we had synchronized global growth, confidence had spiked to record post-war highs, and everyone knew we had this steroid-induced earnings boost coming. The thought was how could stocks lose, and of course they did."

The market has sprung back from December's low, with the S&P gaining 15 percent since Dec. 26.

"This year, we came in with nothing but bad news — the economy was slowing down. ... The rest of the world is slowing. We have trade wars. We have the shutdown, and analysts are revising earnings lower," Paulsen added. "We're worried about a recession and a bear market. It's strikingly different, and yet it's kind of like how can stocks win, but they are and I think they will."

Strategists also point to the differences in the way the market traded in each January. This January has been full of volatile swings, with ultimately larger gains than losses. Last year, the market was at the end of a long smooth glide path higher.