With a monster gain in 2023 that exceeds the Nasdaq Composite index, Apple (AAPL 2.48%) is again showing that it's a favorite among the investment community. And this is much needed, particularly after the stock lost an eye-watering 27% of its value in 2022. But now, with Apple shares getting close to an all-time high again, the question is this: Should investors buy, sell, or hold this leading consumer discretionary stock?

Facing a slowdown

Macro headwinds have been negatively impacting Apple in recent quarters. The company's revenue totaled $383 billion in fiscal 2023, which was down 2.8% year over year. This was the first annual sales decline since fiscal 2019. Yet, investors seem to have shrugged off this news. The stock has climbed about 7% since the announcement.

In the latest quarter, all product categories showed revenue drops, except for the iPhone. But while it was encouraging that the company's flagship product registered growth, with management even saying that iPhone 15 sales were doing better than iPhone 14 last year, CFO Luca Maestri said Apple's overall revenue in the current quarter will be "similar to last year."

The forecast for a lack of top-line gains, especially during the key holiday shopping season, is a troubling sign. It just might indicate that Apple will continue to face pressures in the near term.

Economic moat

But there are reasons to have a positive attitude about this business. Apple possesses a wide economic moat that has supported its remarkable success over the years, and should continue doing so in the future. In short, it has a powerful brand. Its popular hardware products carry a premium status in the industry, with the business exhibiting proven pricing power that hasn't deterred consumers from paying up.

That's why Apple products carry a stellar gross margin of 37% (for fiscal 2023). This is really impressive and bucks the reputation of consumer electronics being a terrible business that must always deal with falling prices.

Additionally, Apple is bolstered by what I would call "invisible" switching costs. Of course, there's nothing stopping any Apple customer from buying what a rival company offers. However, Apple's ecosystem, which consists of not only its hardware products, but also various software and services, helps to keep consumers locked in.

And with many of your friends and family likely using Apple products and services as well, there's almost no incentive to leave.

What should investors do?

Apple's stock has soared this year, and as a result, it's not cheap. The price-to-earnings (P/E) ratio of 31 is about 50% more expensive than the trailing-10-year average of nearly 21. For a mature business that depends on a product like the iPhone that is almost saturated in its most important markets, I view the chance for market-beating returns going forward as slim. This is why I don't recommend investors buy shares today.

On the flip side, the case to sell the stock may make sense. If you've been a longtime Apple shareholder, and you're sitting on fantastic gains, then it could be a smart idea to take at least some of the profits off the table -- especially if there are other attractive investment opportunities you are eyeing right now.

Readers might also just want to follow what Warren Buffett is doing. The conglomerate he runs, Berkshire Hathaway, owns 5.9% of Apple's outstanding shares, representing more than 48% of the company's equity portfolio. Berkshire remains an Apple owner. Maybe this is because of the dividends the tech giant pays, or that its share buybacks continue to increase Berkshire's ownership position.

Buffett might also not know where he would park that capital if he fully exited the Apple position. Nonetheless, while it's a great business, I don't think Apple is a buy right now.