It often pays to look at a long-term chart for some perspective. Yahoo! Inc. (YHOO) has been rallying aggressively since the start of 2016, but the company is unprofitable and based on analyst estimates has a forward P/E of 64. It would seem that much of the expected upside in the stock is already priced in, and potentially overdone. The charts agree.

A 5-year weekly chart reveals a massive uptrend from 2012 to 2014. The stock then lost as much as half of its value in 2015, before rallying in 2016.

The decline in 2015 made a significantly lower swing low than it did in 2014. This marked the potential start of a larger downtrend. Downtrends are composed of declines, pullbacks to the upside (where the stock is now) followed by another major decline. The rally in 2016 and early 2017 is potentially a bear market rally, where the price doesn't move above the 2014 high ($52.62), and instead declines back toward $30 or below.

On the weekly chart, a decline below $40 would break the rising trendline of the bear market rally. That downside breakout would align short-term momentum with the longer-term bearish outlook. Also on the weekly chart, a large head and shoulders pattern is forming. This pattern is not complete yet, but if the price can't eclipse the 2014 high and then drops below the rising trendline from 2016, that would increase the probability of the head and shoulders completing in the future.

$30 to $26 is a potential support area and the first target if a decline develops. If the price drops below support over the longer-term, the next target is $13. This latter target is based on a breakout of the shoulders pattern, in percentage terms. The difference between the high and low (support) of the pattern is approximately 50%. Therefore, a drop below support could indicate the price is cut in half again, giving a target range of $15 to $13. That is where the stock spent a lot of time between 2009 and 2012.

Even if the stock can reclaim the $50 region, there is the potential for a double top, similar to what happened in 2005. At that time, the price was experiencing a strong uptrend and made a higher high, but then quickly reversed into a long-term downtrend.

While valuations are lofty for Alphabet Inc. (GOOG) as well, it may present a better investment. It is trading at about 1/3 the of the forward P/E of Yahoo!. The forward P/E for Alphabet is still lofty, though, at 21. Alphabet's stock is moving in a giant wedge pattern since the middle of 2015. Wedges often occur at the tail ends of trends. A decline below $775 would break the wedge on the weekly chart, signaling a further decline. Since Alphabet is a consistently profitable company—with a consistent track record for growing earnings—that decline would present a long-term buying opportunity.

Look to buy Alphabet near $680. That is a 20% decline from the current price of $850. Long-term charts reveal that 15% to 30% pullbacks are quite common.

The Bottom Line

Using a 20% decline to get into the long-term rising Alphabet is more attractive than trying to pick a bottom in Yahoo!. Right now Yahoo! is being carried higher on potential. If the company can't deliver—and the company's ability to do so is checkered—Yahoo! stock could be in for a significant decline. Alphabet is also trading at a lofty valuation but has a strong track record of growing earnings. While a drop in Yahoo! means likely further declines, a pullback in Google presents a long-term buying opportunity.