The stock market rally in the first half of the year helped one of the world's most famous billionaires score a big win. Bill Gates, co-founder of Microsoft, saw his fortune climb by $4 billion thanks to investments in three companies, according to Barron's.

These gains over a rather short period of time aren't about short-term investing, though. They happened thanks to a long-term investment strategy. Gates, through his Cascade Asset Management firm, has owned the winning shares for years.

Let's find out more about Gates' first-half fortunes -- and how you might follow his lead.

Gains thanks to three companies

Gates founded Cascade back in 1994, and the firm manages much of his fortune. Michael Larson has served as chief investment officer since that time. In the first half of this year, Cascade's gains came as shares of waste management company Republic Services (RSG -0.85%), car dealer AutoNation (AN 5.92%), and water treatment specialist Ecolab (ECL 0.60%) soared, Barron's reported.

The investment firm holds 35%, 21%, and 11% of these companies, respectively, the report showed. The Cascade position makes Gates the largest shareholder in these companies. The three stocks have climbed in the double digits since the start of the year.

RSG Chart

RSG data by YCharts

And these companies have shown strength over the long term, too. They've advanced at various rates over the past five years, as shown in the chart.

RSG Chart

RSG data by YCharts

Cascade's position in another top company limited the gains. That's after Deere slipped about 5%. But it's important to remember that the maker of agriculture and lawn care equipment rose 25% last year. And Deere has soared in the triple digits over the past five years.

So, clearly Gates' successes are linked to his commitment to companies over the long term. These positions "reflect Cascade's patient and fundamental approach to long-term value investing," Larson told Barron's in an emailed statement. And Gates has said in the past, "Patience is a key element of success."

How you can apply Gates' strategy

Now let's get to how you can apply this when investing -- and possibly score gains over time. Cascade didn't have to buy up a bunch of shares early this year to benefit from this year's rally. The firm already was invested in stocks it considered promising.

That means that we shouldn't wait for the market to take off to start buying, either. Every day -- regardless of the market environment -- represents an opportunity to find a terrific stock. And in difficult markets, we often have the chance to pick up some top stocks at very interesting prices. 

For example, last year, as markets reached bear territory, Gates' stock AutoNation slipped below $100 a share. AutoNation has since gained more than 70% from that point. But that doesn't mean it's too late to buy the stock. It's still trading considerably lower in relation to trailing-12-month earnings than it was a few years ago -- meanwhile, revenue has soared.

AN PE Ratio Chart

AN PE Ratio data by YCharts

So, even among stocks that have rallied, there are buying opportunities.

Now, let's talk about the importance of holding for the long term -- by this, I mean at least five years. This gives companies time to recover if they've faced tough times. And it gives them time to grow if they are early in their growth stories. Or both. And it offers investors time to benefit from these stages -- and resulting share performance.

All this means if you're already heavily invested in stocks -- wonderful. Like famous billionaire Bill Gates, you may benefit over time by holding on to promising players. And if you're earlier in your investing journey, any time is the right time to start buying stocks with bright long-term prospects.