Gold ends near 3-week high as dollar sinks