The S&P 500 just reached an all-time high, but that doesn't mean that all stocks are expensive. There are some compelling opportunities -- especially in the technology sector -- that could be great long-term investments for those who buy now.

Here are two in particular that could be excellent investments for people who prefer to measure their returns in decades. I own both in my portfolio and plan to keep them for as long as their management teams keep their growth momentum alive.

A powerful fintech with lots of optionality

For a while, Block (SQ -4.16%) appeared to have a somewhat disjointed growth strategy. That's changed. CEO Jack Dorsey and his team have refocused their efforts on their core businesses of Cash App and Square (still the name of the small business side). They're doubling down on efficiency, with moves like a cap on the number of employees and new cost controls.

There's clear momentum in the business. In the most recent quarter, gross profit grew by 21% year over year, and adjusted earnings before interest, taxes, depreciation, and amortization (EBITDA) was up by 46%. Cash App's growth is especially impressive (27%), and certain new initiatives, such as the Cash App Borrow short-term credit product, have gained a lot of traction.

Management clearly agrees that the stock is cheap, implementing a $1 billion buyback program recently. There are especially interesting opportunities when it comes to adding more (monetizable) banking services on both sides of the business and expanding into more international markets.

Could this be a top AI stock to buy?

Metaverse technology is still in the very early stages, and Roblox (RBLX -0.47%) could be one of the biggest winners as it evolves. As more immersive wearable technology rolls out over the next few years, it could drive long-tailed growth in use of the gaming platform.

The recent numbers have been fantastic. In the third quarter of 2023, Roblox grew both its bookings and daily active users by 20% year over year. Operating cash flow grew 68%, and the company expects capital expenditure growth to slow down significantly, as the data center it has been building is nearly complete.

This could be just the beginning. Roblox has said that it eventually wants to bring 1 billion people into its platform (about 70 million DAUs currently). The metaverse market is estimated to be about $84 billion in size as of 2023, but is expected to grow rapidly, reaching $1.3 trillion by 2030. If the technology keeps evolving and Roblox continues to grow and innovate, it could be a home run for patient investors.

Don't expect a smooth ride

Long-term investors need to manage their expectations, especially when it comes to buying high-growth stocks like these. First, there is a lot of execution risk involved with both -- meaning that there's a lot that needs to go right for these stocks to deliver market-beating returns. Second, even if things go well, these are likely to be volatile stocks, and the path higher won't be a straight one.

As a personal example, since I first invested in Block shortly after its IPO, the stock has gone from about $10 per share to a peak of $280 and back to the current level of about $63. If you buy either of these stocks to hold for the long run, be willing to deal with price swings like that along the way.