The broader stock market is near all-time highs, but that doesn't mean all stocks are. Remember, the stock market is a market of stocks, not a single entity. Despite the index's success, the S&P 500 is littered with stocks nowhere close to their highs.

That's a potential buying opportunity for long-term investors who can identify broken stocks while avoiding broken businesses. Sometimes, stocks decline for short-term reasons or no reason at all. So, I combed the S&P 500 for some magnificent stocks down on their luck.

Here are three stocks down 17% to 44% that are great investment ideas to buy and hold forever.

This home improvement giant has slumped

The Home Depot (HD -1.65%) saw its sales slump by 3% in 2023. However, one should also acknowledge that sales have surged since the pandemic. Stimulus and strong consumer spending helped people invest in their homes, which ignited robust growth at the home improvement giant. Of course, Wall Street is a "what have you done for me lately?" game, but you don't have to play it that way.

The stock is about 17% off its high, trading at roughly 22 times this year's expected earnings. This is an opportunity to look at the bigger picture. Management estimates the home improvement market is worth $950 billion, and Home Depot, the largest home improvement retailer in the world, is at $152 billion. That's a 16% market share, meaning it's a fragmented industry. Home Depot enjoys leverage with suppliers and can sell at lower prices due to its massive size. One could reasonably expect Home Depot to continue taking market share over time.

HD Revenue (TTM) Chart

HD Revenue (TTM) data by YCharts

The business is highly profitable. Management has bought back enough stock to retire over a quarter of outstanding shares in the past decade alone. Additionally, Home Depot has raised its dividend for 15 consecutive years, and the most recent 7% increase is a vote of optimism from leadership. As an aside, analysts expect the business to grow earnings by an average of 10% annually over the next three to five years. Don't make this harder than it needs to be. Home Depot is a fantastic business trading at a fair price. It's a stock you scoop up in these situations and never let go.

High rates have tripped up this quality REIT

Realty Income (O -2.47%) is a famous dividend stock. The Monthly Dividend Company is a real estate investment trust (REIT), a business that leases real estate. Realty Income buys and leases single-tenant properties, focusing primarily on recession-proof tenants in the retail sector. A typical tenant for Realty Income might be a grocery store, a dollar store, a movie theater, or a gym. The company has paid and raised its dividend yearly since going public, a streak currently at 31 years and counting.

REITs must pay most of their taxable income to shareholders, so they often rely on borrowing to fund expansion. High interest rates on debt make borrowing more expensive, which can pressure companies like REITs that borrow a lot. You can see that Realty Income's stock has reacted negatively as the 10-year Treasury (a stand-in for interest rates) yield increased:

O Chart

O data by YCharts

Shares have fallen to the point that investors are getting a starting dividend yield of 5.6%. Meanwhile, the stock trades at just 13 times its funds from operation, which REITs use instead of earnings. Even mid-single-digit growth out of Realty Income could produce double-digit total returns, so it's hard not to like the stock as a buy-and-hold.

This Dividend King is still bouncing back

Altria (MO -0.02%) hasn't been the best investment over the past few years. In 2018, the tobacco giant and Marlboro maker spent $12 billion on a stake in electronic cigarette company Juul, but the investment blew up in Altria's face, ultimately becoming worthless. Shares haven't recovered since then and remain down over 40% from their former high. Ironically, now might be the best time in years to consider owning the stock.

First, this Dividend King's massive payout yields over 9% and has never been at risk. Despite declining smoking rates in America, Altria's dividend payout ratio remains a comfortable 75%, thanks to the pricing power that nicotine products hold. Second, the stock's valuation has become mesmerizingly cheap. Shares trade just over 8 times earnings, a low bar that can produce investment returns, even with single-digit earnings growth.

MO Cash Dividend Payout Ratio Chart

MO Cash Dividend Payout Ratio data by YCharts

What could seal the deal is management's recent decision to accelerate share repurchases by selling a piece of its multibillion-dollar stake in Anheuser-Busch. It's a sign that management is not only aware of the value its stock trades at but a vote of confidence in Altria's future. The company is pivoting to smokeless nicotine products, including vapes, heated tobacco, and oral nicotine pouches. You're buying this stock for that juicy dividend, which the facts point to years of tread left on those tires.