History doesn’t repeat itself, but it does rhyme, Mark Twain probably never said.

That’s most true in financial markets, where bullish and bearish phases follow certain clear, discernible patterns. “Bull markets are born on pessimism, grow on skepticism, mature on optimism and die on euphoria,” the late, great Sir John Templeton surely did say.

Problem is, when you live through a bull or bear market, you’ll likely get swept up in the prevailing sentiment and will be unable to put things in perspective—especially if you’re young or new to investing.

Which brings us to a report by TD Ameritrade about the investing habits of the much-chronicled millennials, who are rapidly replacing baby boomers on the economy’s center stage.

According to TD Ameritrade, the five stocks most owned by its millennial customers are—wait for it—Apple Inc. AAPL, -3.17% , Facebook Inc. FB, -0.89% , Amazon.com Inc. AMZN, -1.78% , Tesla Inc. TSLA, +4.42% , and Netflix NFLX, -0.05% , almost all staples of millennials’ daily diet. (Few millennials can afford to drive Teslas, but they’re way cool, so I guess it counts.)

Capitalism summer camp for ​grade-schoolers

These also have been among the market’s hottest stocks over the past few years, until the recent selloff took some wind out of their sails. None of the millennials’ top 10 stocks pay boring old dividends, Steven Quirk, executive vice president of TD Ameritrade’s Trader Group, told CNBC.

Quirk said nearly half of the firm’s millennial clients trade on their mobile devices, twice as much as the overall customer base. They “all trade the same” social media stocks, he said, including hip losers Snap Inc. SNAP, -1.97% and Twitter Inc. TWTR, +2.03% , both now below their initial public offering prices, as millennials invest in what they know.

Those of us who’ve been around for a while have seen this movie before, and it looks like a bad sequel, like “Alien: Resurrection” or “Pirates of the Caribbean: Dead Men Tell No Tales.”

Not so long ago, before the turn of the Millennium, novice investors, caught up in the giddy potential of an internet that was going to “change everything,” threw gobs of money into fly-by-night dot-coms and solid technology companies like Cisco Systems CSCO, -1.38% . Many of these “investors” may be parents of millennials, who were born roughly between 1981 and 1997.

A famous E*TRADE ad from that era urged investors to “boot your broker” and trade online. Thousands followed that advice, sometimes quitting their real jobs to day trade hot stocks like Yahoo and internet incubator CMGI (which gained almost 5,000% in five years) dozens of times a day. Sure, they used clunky old desktop PCs rather than sleek iPhones, but the result was exactly the same: Very few made any money.

Nobody expected the merry-go-round to stop, but of course it did, and even non-day-trading investors, who had bet heavily on technology and the internet, lost their shirts. The S&P 500 SPX, -1.11% tumbled 49% and the Nasdaq Composite Index COMP, -1.07% lost an astonishing 72% of its value. Some people who had lived through this grim experience swore off investing forever.

How the rise of drones is posing a major security nightmare

And now, it seems, some millennials are making the same mistakes. The smartphone makes it much easier to trade online; you can do it in your Uber car or while waiting in line at Starbucks. But the research is conclusive: The more you trade, the worse you’ll do.

And while writing teachers’ famous mantra “write what you know” is generally good advice, “invest in what you know” isn’t. Why? Because people have only superficial knowledge of companies or industries yet think they’re experts.

Even Peter Lynch, the superstar fund manager of Fidelity Magellan Fund who popularized that maxim in his best-selling book, “One up on Wall Street: How to Use What You Already Know to Make Money,” warns against misinterpreting his advice.

In 2015, Lynch, who retired from investing 25 years earlier at the top of his game, told The Wall Street Journal: “I’ve never said, ‘If you go to a mall, see a Starbucks and say it’s good coffee, you should call Fidelity brokerage and buy the stock.’”

The common wisdom of “buy what you know” leaves out the hard fundamental research on companies at which Lynch and his team excelled. “’People buy a stock and they know nothing about it,’” he told the Journal. “’That’s gambling and it’s not good.’” No, it’s not.

Ironically, only one in three millennials says they invest in stocks at all, according to Bankrate, and those who don’t say the market is too risky. The Investment Company Institute reported millennials are more heavily invested in employer-sponsored retirement plans than boomers and started investing earlier. They also are gobbling up target-date retirement funds, a decent diversified solution for most people’s retirement investing.

But those who are loading up on the trendiest stocks should beware the siren song, “this time is different.” Ask your parents: That way leads only to tears.

Howard R. Gold is a MarketWatch columnist and founder and editor of GoldenEgg Investing, which offers exclusive market commentary and simple, low-cost, low-risk retirement investing plans. Follow him on Twitter @howardrgold.