Gold prices end with a gain, with dollar index near session lows