The Trump-China trade war has been bad for stocks — but good for bitcoin.

Turmoil in global stock markets sent the price of the controversial digital coin up more than 7% Wednesday as a falling yuan sent Chinese investors fleeing, according to experts.

That’s because bitcoin, which touts itself as a global currency, is viewed by many Asian investors as a safe haven.

Gold, the original safe haven, also rose on renewed tariff fears, gaining 1.5% to $1,461.30 per ounce, according to precious-metals data provider Kitco Metals.

The price gains came as China let its currency fall below 7 yuan to the dollar — an 11-year low that prompted Trump to accuse Beijing of manipulating its currency amid an escalating trade war.

Michael Novogratz, the former Fortress Investment Group principal who founded cryptocurrency investment firm Galaxy Digital, predicted the global unrest would extend this year’s bitcoin rally.

“$Btc rally could have real legs,” he tweeted on Monday, citing a foreign exchange war, instability in Hong Kong and “the beginnings of capital flight.”

Gun stocks also posted increases early Monday after the weekend’s tragic massacres in Texas and Ohio had macabre investors anticipating a rush by consumers to buy firearms ahead of calls for stricter gun laws.

American Outdoor Brands Corp., the parent of Smith & Wesson, jumped 2.4% in morning trading, while Sturm Ruger & Co., maker of the AR-556 autoloading rifle, gained 1.3%.