As the first quarter comes to an end, the bond market is calling for a recession for the first time in more than a decade, leaving investors scrambling to figure out what to buy and sell. If history is any guide, there's a pattern in the stock market to follow.

The spread between the 3-month and 10-year Treasury notes fell below zero last Friday, and is still negative as of Thursday, sending the biggest recession signal since 2007 as the inversion has predicted every recession in the past 50 years.

While the stock market is still on track to post its best quarter sine 2012, thanks to the epic rebound in the first two months of 2019, the rally seems to be on hold and volatility has made a comeback.

Now, which stocks would work the next quarter and beyond if this red flag from the bond market turns out to be right and the economy is in trouble?

CNBC analysis using Kensho, a hedge fund analytics tool, found which sectors have been biggest winners and losers during the past eight times the 3-month and 10-year Treasury yield curve inverted. The analysis looks at the one-month, three-month and six-month performance of all the S&P 500 sector indexes after the inversion.

The data show the utilities, consumer staples and health-care sectors top the list of biggest gainers after the bond market flashed the recession signal. It's no surprise that these sector are winners as they have been typical defensive plays in a risk-off environment because of their stable growth and high dividends.

The S&P 500 utilities sector has posted a nearly 10 percent gain on average six months after the yield curve went upside down, while the S&P 500 consumer staples sector scored an 8 percent return, Kensho data show. The on average has lost 0.19 percent six months after an inversion.

On the flip side, information technology has been the biggest loser, bleeding more than 13 percent on average in the six months post a yield curve inversion. Investors likely flee these hot stocks during times of fear in the market. Communication services has also been a laggard, losing 7 percent on average during the same period of time.