Gold ends higher, but retreats from 5-month high as dollar strengthens