Investors often fear bear markets. But as much as we enjoy bull markets, we also need to embrace the bumpy periods too as part and parcel of how the markets work. We can learn to appreciate these periods by having a solidly diversified portfolio of stocks that work for us in different investing environments -- and by using bear markets to identify companies with strong, long-term opportunities that should soar when the bull comes back.

I want to recommend four stocks to buy in the next bear market. Two of them can help shield your portfolio when times are rough, and two of them are trading at high valuations and can become better values if prices fall. The first two are Realty Income (O -0.71%) and Costco Wholesale (COST -1.78%), and the second two are Square (SQ -4.53%) and Shopify (SHOP -2.04%).

A man and woman pushing a shopping cart filled with groceries in a parking lot.

Image source: Getty Images.

Realty Income: A stable and growing dividend

For income investors, there's a lot to love about Realty Income. Most notably, it pays a monthly dividend instead of the more common quarterly dividend, and it has paid it for 615 months in a row. What's more, the company raises the dividend quarterly, and it's done so for 96 consecutive quarters.

Realty Income operates as a REIT, or real estate investment trust, and it owns more than 6,700 properties globally. Its largest tenants, such as Walgreens and FedEx, are mostly companies that sell essentials -- and so do well even in economic downturns. That gives Realty Income stability, and it means you can trust its dividend. 

Realty Income is merging with VEREIT, a similar property owner, which will bring its holdings to more than 10,000 properties and make it one of the biggest REITs in the world. That's even more security for shareholders.

Costco: The case for low prices

Big-box retailer Costco has had a steady and growing stock price for years, nearly doubling the S&P 500's gains over the past 10 years. It barely registered the March 2020 market crash, and it's performed similarly well during other market pullbacks.

That's because its core model of selling products with razor-thin margins means great deals for members, who flock to the company's warehouses in all types of economic environments. Sour times often work in its favor since members (who pay an annual fee of $60 for a standard membership or $120 for an executive membership) shop at Costco to get the most out of their memberships and take advantage of its prices.

Costco's sales shot up when the pandemic started, growing in low double-digits year over year, and they remain elevated even as other pandemic winners have seen their growth return to normal levels. Its stock price is up 20% year to date, and it pays a growing dividend that yields 0.68% at the current price.

A man sitting at a table with a computer and a woman standing next to him.

Image source: Getty Images.

Square: High-growth fintech

Digital payments processor Square has seen its stock gain more than 2,000% over the past five years, but it still has massive growth prospects. In the past year alone it's launched several new products, including trading in Bitcoin and stocks as well as a savings account, all on its Cash App.

It's also expanding its sellers business to target more medium-size and large businesses, a step away from its core small-business customers, and it announced a recent deal with TikTok to integrate with the Square sellers platform.

Its growth strategy is paying off with $4.7 billion in second-quarter sales -- up 143% over last year -- and $250 million in net income vs. a loss in the second quarter of 2020.

Square is a fintech leader that's only just beginning. It's also super-expensive, with its stock trading at 225 trailing 12-month earnings. That premium might be justified, but Square stock is definitely one to consider if the price comes down.

Shopify: Powering e-commerce

The stock of Shopify has been a fantastic investment, gaining more than 3,000% over the past five years. But it's always been expensive and currently trades at 70 times trailing 12-month earnings. But it still has so much opportunity ahead, and it has demonstrated that it has the tools and team to keep growing.

The company, which sells customizable e-commerce platforms, sees a total addressable market of $153 billion. It works with an extensive range of companies, from small ones (for a $29 monthly fee) to large ones (which can cost more than $2,000 a month), giving it a far reach. It also offers several products, giving it a broader growth runway. Shopify has grown to become the second-largest e-commerce company in the U.S. with almost 9% of the market, behind only Amazon.

As you might imagine, 2020 was a huge year for Shopify as e-commerce became much more important under lockdowns. It posted an 86% year-over-year sales increase. But it's not suffering in 2021. Sales increased 57% in the second quarter. And although its merchant count jumped last year, it's still growing, albeit at more typical rates.

Shopify is a great company with strong growth prospects. Investors should consider buying its stock -- and particularly if the price goes down.