Fear about slowing growth and the prospect of lower interest rates have been pushing the price of gold higher.

But analysts say the metal may be nearing the top of its run for now, and whether it continues to gain depends on whether the markets continue to fear trade wars will dampen global growth.

Gold futures had been struggling this year to hold above $1,300 and once the price broke $1,279 in recent sessions, analysts said that set the stage for a move higher. Gold futures for August were higher by more than $5 to $1,334 per ounce Wednesday afternoon, and are up 5% since the beginning of May.

On Wednesday, the dollar was higher and Treasury yields were lower. Stocks were also higher, both on expectations the Fed would cut interest rates and hopes the U.S. would not slap tariffs on all Mexican goods next week, as threatened by President Donald Trump.

"Right now you have to take into account that it had a good run and also that we still have a firm dollar going forward," said James Steel, chief commodities analyst at HSBC. The dollar and gold often move in opposite directions. Steel said he expects gold to reach a high of $1,372 by the end of the year, but it may stop for a period before it heads higher.

'I think the market is in need of some consolidation right now," said Steel.

Bart Melek, head of commodities strategy at TD Securities, said he also sees the rally getting close to a peak for now.

"It's been a nice run," he said, adding he does not see the market breaking above the year highs of $1,346. "I think the market is a little overly optimistic on their Fed view. A lot of people expect as many as three cuts this year, starting in June. I don't think that's on. Yes the U.S. economy is slowing, and Mr. Trump has added to the uncertainty."

Strategists say the buying interest in the metal picked up dramatically right after President Donald Trump tweeted that he would put tariffs on all Mexican goods. That also increased worries about economic growth, sent buyers into Treasurys, and raised expectations that the Fed would now not only lower interest rates. but maybe even cut twice this year.

The gold buying also drove up ETFs, and SPDR Gold shares is up 4% since early May.

"I do think the rally has some legs," said Steel, head of precious metals analysis at HSBC. "It's gone sharply higher in just a few days so one has to accept that the rally may need some period of consolidation. The increase in financial market volatility, and trade-related and geopolitical risks are what's behind this."