Gold settles with a gain after turning higher near the session's end