Gold ends with a slight gain after trading lower for most of the session