The U.S. stock market is more overvalued than it was at the majority of the past century’s peaks, according to six well-known valuation ratios.

That doesn’t mean the bull market is coming to an end, of course, since some past bull markets were even more overvalued when they topped out. Furthermore, no two market peaks behave the same way.

Dan Neil's Best and Worst of the Detroit Auto Show

Nevertheless, the evidence suggests that risks are high. You may want to consider selling some of your stock holdings and building up cash.

To compare current valuations to those that prevailed at past market tops, I relied on a comprehensive list of past bull-market tops compiled by Ned Davis Research. The list is based on a set of criteria focusing on the speed, magnitude and length of market movements.

According to the firm, there have been 35 bull-market tops since 1900. The Dow Jones Industrial Average lost an average of 31% in the bear markets that followed.

Here’s how the market stacks up to past market tops according to these six valuation ratios.

Price/earnings ratio. Calculated by dividing stock price by earnings per share, this is perhaps the most widely followed of all valuation ratios. Based on the previous 12 months’ earnings, the S&P 500’s current P/E ratio is 18.6, which is higher than those that prevailed at 24 of the 35 bull market tops since 1900. (Data before 1957 are for the S&P Composite Stock Index, since the S&P 500 didn’t exist yet.) Cyclically adjusted P/E ratio. This is the version of the P/E championed by Yale University Professor Robert Shiller, the recent Nobel laureate in economics. It is calculated by dividing a company’s stock price by the average of its inflation-adjusted earnings of the preceding decade. For the S&P 500, this ratio currently stands at 25.6, which is higher than what prevailed at 29 of the 35 tops since 1900. Dividend yield. This is the percentage of a company’s stock price that is represented by its total annual dividends. Since this yield tends to fall as prices rise, and vice versa, the market should register some of its lowest readings near its tops. The S&P 500’s yield currently stands at 2.0%, which is lower than the comparable yields that prevailed at all but five of the bull-market tops since 1900. Price/sales ratio. This is calculated by dividing a company’s stock price by its per-share sales. Though it is lesser known, it still is championed by many investors because it is based on data that are less susceptible to manipulation than earnings. For the S&P 500, the price/sales ratio currently stands at 1.6, which is higher than the comparable readings that prevailed at all but two of the bull market tops since 1955, which is how far back data are available. Price/book ratio. This is another lesser-known valuation indicator, calculated by dividing a company’s stock price by its per-share book value—an accounting measure of net worth. For the S&P 500, this ratio currently stands at 2.7, which is higher than all but five of the 28 bull-market tops since the mid-1920s, which is how far back data are available. “Q” ratio. This indicator is based on research conducted by the late James Tobin, the 1981 Nobel laureate in economics. It is similar to the price/book ratio, except that book value is substituted by the replacement cost of assets.

Mr. Tobin thought this to be superior since he considered replacement cost to be better reflection of a company’s net worth than book value, which is based on assets’ original cost — no matter how far in the past those assets were acquired.

The Q ratio currently is higher than what prevailed at 31 of the 35 past market tops, according to data compiled by Stephen Wright, an economics professor at the University of London, and Andrew Smithers, founder of the U.K.-based economics-consulting firm Smithers & Co.

While each of these valuation ratios has its detractors, it is noteworthy that all six of them are currently telling a similar story. It is also worth noting that a particularly bearish message is coming from the two that, according to Messrs. Smithers and Wright, have the best historical track record — the Q ratio and the Shiller P/E.

If you agree with this bearish assessment, you should be thinking of ways to build up cash in your portfolio. At a minimum, you shouldn’t automatically reinvest the proceeds when you sell any existing stock positions.

Market timing is notoriously difficult, however, so you might choose to stick with your stock positions through thick and thin. In that event, you could still begin to shift your stock holdings toward sectors that historically have performed the best near the end of a bull market.

According to Ned Davis Research, those sectors tend to be consumer discretionary and consumer staples. Two exchange-traded funds benchmarked to those sectors are the Consumer Discretionary Select Sector SPDR XLY, -1.39% and the Consumer Staples Select Sector SPDR XLP, -0.91% . They both charge annual fees of 0.18%, or $18 per $10,000 invested.