Canada's main stock index climbed for the fifth straight week on Friday as bank stocks advanced and shares of energy and resource companies rose alongside oil and gold prices.

The energy sector gained 0.6 per cent as oil prices were lifted by strong Chinese oil import data, as well as by turmoil in the Middle East. U.S. crude prices settled up 1.7 per cent at US$51.45 a barrel.

Canadian Natural Resources (CNQ.TO) was among the biggest lifts to the index, rising 1.4 per cent to $41.21, while Cenovus Energy (CVE.TO) advanced 2 per cent to $12.14.

The materials group, home to precious and base metals miners and fertilizer companies, added 0.5 per cent, with Potash Corp (POT.TO) and Agrium Inc (AGU.TO) both up 1.9 per cent. Potash closed at $24.15, while Agrium ended at $134.75.

Gold miner Agnico Eagle Mines (AEM.TO) was up 1 per cent at $58.33. Gold futures rose 0.8 per cent to above $1,303 an ounce after weak U.S. inflation data dampened the case for interest rate increases. 

"There was a little reversal yesterday, things were sent lower by oil prices. We came in this morning and we had gold up through $1,300 and oil up on the day," said Bruce Latimer, senior equity trader at Eight Capital, adding that the strong commodity prices bode well for the TSX.

"The market opened stronger and basically held that gain all day."

The Toronto Stock Exchange's S&P/TSX composite index, which was up 0.5 per cent on the week, finished 64.97 points, or 0.41 per cent higher, to close at 15,807.17.

The index eked out a new 7-1/2 month high and its fifth consecutive week of gains. That is the longest streak since a five-week run that ended in November 2014.

All but one of the index's 10 main groups were in positive territory, with the healthcare sector down 0.7 per cent.

The Canadian market also joined a global equity rally on Friday, with world stocks up for a fourth day on investor expectations of broad global growth. 

The gains in recent weeks have put the stock market in sight of the intraday record hit last February, which is now less than 1 percent away.

On the domestic data front, Canadian home resales rose in September, led by the major cities of Toronto and Vancouver, and suggesting national sales may be stabilizing after cooling in the spring.

The real estate subsector climbed 0.2 per cent.