The S&P 500 (SNPINDEX:^GSPC) had another strong year, picking up more than 20% on a total-return basis in 2017. That marked the index's best performance since 2013 and extended the bull market string of gains to nine years. Yet when you look at the index's components, just four S&P 500 stocks managed to double from where they began the year. Below, we'll discover more about those four companies -- including which one was taken out of the index during 2017 -- and whether they can keep doing well in 2018.

NRG Chart

NRG data by YCharts.

NRG powers up

The biggest gainer in the S&P 500 in 2017 was NRG Energy (NYSE:NRG), which managed to recover fully from its downturn in 2015. What made the difference for the wholesale power company was a major strategic shift, reversing it's earlier decision to emphasize renewable energy-based generation in favor of going back to a more traditional model based largely on natural gas and coal. The move flies in the face of what progressives in the industry see as the future for electrical generation, but shareholders applauded NRG's move and have pushed shares higher ever since.

NRG stands to benefit substantially as long as prices for fossil fuels remain low. Both natural gas and coal prices have struggled recently, and many see plentiful supplies continuing indefinitely as the drive toward shale-area production continues. If prices ever rise, the resulting cost increases could hurt NRG, but investors are happy with the power company's long-term prospects right now.

Numbers 2017 spelled out in sparklers, with fireworks.

Image source: Getty Images.

Align straightens things out

Any parent of teenagers knows that orthodontic treatments can be both expensive and traumatic. That's what makes Align Technology's (NASDAQ:ALGN) Invisalign system so revolutionary, because it seeks to take away the visual stigma of wearing braces while still making it possible to straighten teeth effectively. Originally focusing on adults, Align quickly realized that the much larger market for teens was worth taking more seriously, and the resulting growth has been extraordinary.

Going forward, Align hopes to widen its scope still further, with international markets a prime potential source for future gains. Attempts to make devices that can serve more demanding needs in dentistry could also expand Align's market penetration. With plenty of room to grow, Align looks well-positioned to keep up momentum in 2018.

First Solar gets its time to shine

The solar industry has struggled in an era of low fossil fuel prices, but First Solar (NASDAQ:FSLR) has charted a course to future growth. The company expects an upsurge in demand for its solar panels in the next several years, and it's looking to increase its capacity through expanding its manufacturing base in Vietnam and Malaysia. By 2020, First Solar expects to have roughly 5.4 gigawatts of production, up from previously planned capacity of just 4 gigawatts for the end of 2019.

Some see even greater opportunity for First Solar from possible tariff impositions on competitors. First Solar's thin-film panels would likely be exempt from any trade restrictions on traditional solar panels, and that could give the company a one-time boost to profits by adjusting pricing accordingly. Even without such measures, First Solar has its strategy in place and is optimistic for the coming years.

Yet despite First Solar's gains, the solar company was removed from the S&P 500 in March. At the time, the company's market capitalization had fallen enough to warrant the move. Now, though, the stock has risen enough that First Solar could get added back to the index if it can stay on track with its growth strategy.

Vertex looks healthier

The pharmaceutical sector, in general, has been mixed, with some concerns about regulation and price controls weighing on growth prospects. Yet Vertex Pharmaceuticals (NASDAQ:VRTX) has remained laser-focused on its impressive stable of cystic fibrosis treatments, and extremely positive early and mid-stage clinical trial results in July were primarily responsible for much of the stock's gains for the year.

Vertex already has the established drugs Kalydeco and Orkambi to treat cystic fibrosis, but their application is fairly limited. By looking at combination drugs, Vertex hopes to allow more patients to use them, and the result could be nearly complete coverage of the universe of those suffering from the disease. The high price of its treatments could become problematic if government regulators seek to limit healthcare spending or if lawmakers put pressure on pricing practices. For now, though, Vertex is in a strong position to keep looking for ways to treat patients better.

The S&P 500 was a big winner in 2017, and these stocks helped pave the way for the broader index. With continued good momentum, both these winning companies and the S&P 500 more broadly stand a good chance of continuing to deliver gains in 2018.

Dan Caplinger has no position in any of the stocks mentioned. The Motley Fool owns shares of and recommends Align Technology. The Motley Fool recommends First Solar and Vertex Pharmaceuticals. The Motley Fool has a disclosure policy.