(CNBC) U.S. stocks traded lower Friday, the last trading day of the year, but remained within striking distance of all-time highs hit this month .
The S&P 500 traded within half a percent of its record high and was on pace for its best year since 2013. Telecommunications led seven sectors lower, while consumer staples was the top gainer.
The S&P has gained about 20 percent this year, with technology and consumer discretionary the top two performers for the year. Only energy and telecommunications have declined this year.
Advertisement - story continues below
Stocks opened higher but struggled to hold opening gains.