A late rally in resources companies and metal producers helped the benchmark gauge erase earlier losses and close at a seven-month high for second time this week.