Investors should pocket gains after a strong rally in major stock markets and scout bargains in the energy and technology sectors next year, a senior strategist at TD Ameritrade said Tuesday. Equity markets have had an ebullient 2017 with the S&P 500 rising 18.8 percent so far this year and the Nasdaq clocking a 27.7 percent gain. "This has been a tremendous rally, and if you're overweight in certain sectors such as technology, your portfolio might be a little bit out of whack as to what your goals are," said JJ Kinahan, chief market strategist and managing director of TD Ameritrade, which manages $1.16 trillion-worth of assets for its global clients. "Bulls and bears make money and pigs get slaughtered, so taking a little money off the table might not be the worst thing in the world to do," he added. "Put a little money in your pocket and lower the basis for the rest of your investments."

Investment ideas

Kinahan said he sees some value in the energy sector, which has lagged behind its S&P 500 sector peers this year and fallen almost 10 percent year-to-date, despite crude oil "being able to hold that $50 and $55 level pretty convincingly," said Kinahan. He's not alone, with other Wall Street analysts identifying energy stocks as an opportunity next year. "For the first time in this recovery, energy stocks appear significantly undervalued. They currently trade at a 32 percent discount to fair value," said Jim Paulsen, chief investment strategist at The Leuthold Group, in a note earlier this week. "Maybe it's time to lighten up on some of your popular 2017 winners and reallocate toward a sector deeply out of favor."

Traders work on the floor of the New York Stock Exchange. Drew Angerer | Getty Images

The other market opportunity could lie in the technology sector, which "still has room to grow," according to Kinahan, despite the S&P 500 Technology sector already rising almost 38 percent year-to-date. "You have to be a little more selective, but if you look at the last earnings calls, they're talking about growth and they're talking about growth worldwide," he said. Facebook, Apple, Amazon, Netflix and Google parent-company Alphabet — the so called FAANG stocks — have contributed the bulk of the S&P 500's gains in 2017. Kinahan also said the eventual passage of tax reforms in the U.S. could help the financial sector, some stocks in the tech sector and American multinationals. He still sounded a note of caution on the magnitude of the rally. "A lot of the expectations have been built in and with that being said, I think the question is: can the reality of what the corporate rate will be, actually live up to the expectations we've heard for the last six months or so?"

The bitcoin momentum