Investors expected sticky inflation to lift gold prices this year. Instead, the opposite happened.The most actively traded gold contract is on pace to decline for six consecutive months, with a loss of 14% through that period so far. That is a significant drop for an asset that is supposed to be a haven and marks the longest losing streak since September 2018, when prices fell 9.9% over six months.Gold is prized by investors for its usual stability during times of turmoil. Prices jumped near all-time highs earlier this year, shortly after Russia’s invasion of Ukraine upended markets for stocks and commodities. In early March, gold settled at a 2022 high of $2,069.40 a troy ounce. Now, it is down 7.9% so far this year, on pace for its worst annual performance since 2015.Stocks are trading lower than they were in early March. The war has dragged on and concerns about inflation have only intensified. But the haven metal has been stuck in a trading range of about $1,650 to $1,800 since June. Gold recovered some on Friday, rising 0.4% to $1,683.50.The volatility is another example of how the Federal Reserve’s aggressive rate-raising campaign is shaking up all corners of financial markets. Last week’s report that inflation remains stubbornly high all but cemented expectations that the interest-rate hikes will continue. The Fed is expected to announce another big rate increase when it meets this week.Why does that matter for gold? Nervous investors who want safe, boring assets when the stock market is a mess don’t favor just gold. Many of them also like to scoop up Treasury bonds.“The outlook for gold remains vulnerable until the Fed stops hiking rates,” said Tai Wong, a senior trader at Heraeus Precious Metals in New York.Treasury yields tend to move in tandem with investors’ expectations for the Fed’s benchmark rate, so investors these days can get relatively big returns on government bonds. Last week, the yield on the two-year Treasury hit its highest level since 2007. That—plus the fact that Treasurys, unlike gold, offer regular payouts—has pushed many risk-averse investors from gold bug to bond buyer.JPMorgan Chase & Co. analysts forecast that gold prices will keep falling, averaging $1,650 a troy ounce in the fourth quarter. That reflects a growing belief that the Fed is in no position to ease its foot off the rate-hiking brakes.“It’s not a light switch that goes on and off. It’s a dimmer,” said Richard Fisher, former president of the Federal Reserve Bank of Dallas, during a talk hosted by CME Group on Wednesday.The U.S. dollar, another haven, is further complicating matters. Investors looking for a safe bet have also been snapping up the U.S. currency, pushing it near 20-year highs. That has made gold more expensive for overseas buyers, damping their demand.The pain is showing up across gold markets. SPDR Gold Shares, the world’s largest exchange-traded fund backed by physical gold, is down more than 2% in September so far.Investors have pulled money from precious metals-focused mutual funds and ETFs for 12 consecutive weeks, according to Refinitiv Lipper data. That is the longest streak since a 13-week run of outflows that ended in May 2021.Gold prices are off almost 20% from the all-time levels they hit in August 2020, when Covid-19 fueled uncertainty.“Gold’s not as attractive as it was in 2020,” said Ruth Crowell, chief executive at the London Bullion Market Association. The front-month gold futures contract lost $44.50 a troy ounce, or 2.6%, to $1,671.70 last week.To be sure, gold remains a better option than stocks, Ms. Crowell added. The S&P 500 is down 19% this year.Many investors expect the Fed to slow its pace of rate increases next year, which could bring down yields and the dollar, boosting gold prices. The JPMorgan analysts expect gold to rise to about $1,820 a troy ounce by late next year.