* TSX rises 30.38 points, or 0.24 percent, to 12,824.63 * Five of 10 main sectors advance * CN Rail falls 1 percent as results disappoint By John Tilak TORONTO, Jan 22 (Reuters) - Canada's main stock index closed near an 18-month high on Tuesday, led by a rise in gold stocks, which tracked a rally in the precious metal after the Bank of Japan pledged to launch an aggressive stimulus plan. The gains were restrained by Canadian National Railway Co slipping 1 percent to C$93.77 after the country's biggest rail carrier gave a profit outlook for 2013 that fell short of analysts' expectations. Investors have been shifting their attention between macroeconomic concerns and corporate results, and expectations have been muted for the resource sector this quarter. But markets received support from the Bank of Japan announcement that it would switch to an open-ended commitment to buying assets next year and double its inflation target to 2 percent. "Overall, the underlying sentiment is quite positive. It looks like the TSX is on track to test 13,000 points," said Elvis Picardo, strategist and vice president of research at Global Securities in Vancouver. However, the near 18-month high the TSX is at pales in comparison with the five-year high levels the S&P 500 has been touching, he said. The Toronto Stock Exchange's S&P/TSX composite index was up 30.38 points, or 0.24 percent, at 12,824.63, its highest since August 2, 2011. Five of the 10 main sectors on the index were higher. The financial sector, the index's weightiest, gained 0.2 percent. Royal Bank of Canada added 0.7 percent to C$61.76. The materials group, which includes mining stocks, rose 1 percent and played the biggest role of any single sector in leading the market higher. Agrium Inc rose 3.1 percent to C$109.52, and Barrick Gold Corp gained 1.2 percent to C$34.55. The energy sector rose 0.4 percent, with gains at Suncor Energy Inc, up 1.1 percent at C$34.16, and other energy companies, offsetting a decline in Canadian Natural Resources Ltd. The industrials sector slipped 0.2 percent, dragged down by CN Railway. The pullback in the stock is a reflection that it has been doing very well since the start of the year, said Gareth Watson, vice president, investment management and research, at Richardson GMP. "I still think it's a solid story. But I don't think the results that came in justify the big run-up we've had since January," he added.