Gold shakes off losses to finish higher