Trader on the floor of the New York Stock Exchange.

Investors have been flip-flopping between optimism and pessimism for months. But one indicator is warning investors to brace for trouble ahead.

One way to measure the mood of investors is by comparing the S&P 500 High Beta Index versus the Low Volatility Index. When the High Beta Index races ahead, that means investors are looking for thrills and willing to throw caution to the wind in the pursuit of big gains, says Sam Stovall of S&P Capital IQ. But when the Low Volatility Index assumes leadership, that's a signal investors are hunkering down.