One major impetus behind U.S. President Donald Trump’s protectionist policies is his belief that China has artificially weakened its currency in order to dump goods in the United States. Trump harped on this issue often during his presidential campaign. But now that he is taking action to reduce America’s bilateral trade deficit with China, there could be grave consequences for the world economy.

Trump is making a mistake. And yet his views about China’s currency should not come as a surprise, given that exchange-rate management is one of the most complex areas of economic policymaking.

I learned this the hard way while serving as an adviser to the Indian government from 2009 to 2012. After Standard & Poor’s downgraded U.S. long-term sovereign credit from AAA to AA+ on August 5, 2011, I was surprised to see the dollar begin to strengthen. It took me a while to understand what was happening.

Investors were worried that the downgrade could cause global turbulence and began to pull their money out of emerging markets. In earlier times, investors would then have parked some of their money in strong European economies. But, because most of those countries had handed over monetary policy to the European Central Bank and could no longer print their own money, there was a heightened risk of default.

By contrast, the U.S. had its own currency and central bank, allowing it to make good on its debt under almost any circumstances. And investors were also reassured by the fact that the world’s second most powerful economy, China, had a vested interest in a relatively strong, stable dollar, owing to the fact that a large portion of its massive stock of foreign-exchange reserves was held in dollars. Hence, the paradox: though the source of the problem was the U.S., money went rushing to the U.S., strengthening the dollar.

I have had a keen interest in exchange-rate management ever since that episode. In May 2013, when I was Chief Economist at the World Bank, my colleague Aristomene Varoudakis and I published a study examining different exchange-rate policies across a wide range of countries. We found that almost all countries occasionally buy and sell on foreign-exchange markets in order to increase or boost the value of their own currency. In most cases, this is not done directly, but rather by commercial banks acting at central banks’ behest.

China, for its part, has pursued an interesting exchange-rate policy over the decades. Through the 1980s and 1990s, there is no doubt that China kept its currency artificially undervalued so that it could sell more goods internationally. From the mid-1990s to 2005, the renminbi was virtually pegged to the U.S. dollar in nominal terms, and the dollar did experience real appreciation. The logic was simple: by buying dollars, China could cause the relative value of the dollar to rise, which meant that the value of the renminbi would fall. Accordingly, the People’s Bank of China accumulated enormous dollar reserves during this time.

As it happens, Switzerland pursued a similar—albeit shorter-lived—strategy after the 2008 global financial crisis, and particularly after September 2011. During that time, the Swiss National Bank managed to hold down the Swiss franc’s value while accumulating a huge volume of foreign-exchange reserves.

Is this a good strategy? In China’s case, it certainly allowed domestically based firms to export more, but only because they were selling at below-cost prices, thus incurring losses. This approach makes sense if one is selling habit-forming goods, because you can raise prices and make up for earlier losses once the customer has become dependent on the product. Hence, if you were starting a newspaper in the print era, it was generally wise to underprice it until you had built up a large base of loyal readers.

Like certain products, buying from a country can also be habit-forming. Once you have mastered all of the rules and regulations, as well as the culture and politics, of a trading partner, you have an interest in continuing to do business with that country.

With the U.S. and many other nations now hooked on buying from China, Chinese policymakers no longer need to maintain an undervalued currency. And, indeed, China has been spending down its foreign-exchange reserves since mid-2014. Though the renminbi was once kept artificially weak, there are now many economists who believe that it is actually overvalued. That, after all, is what one would expect for the seller of an addictive good.

In this context, Trump’s tariff war comes far too late, and will prove utterly self-defeating. But let’s assume that Trump is right—that China is still selling its products to U.S. consumers at a loss. In that case, my advice to him is simple. He should send a thank-you note to Chinese President Xi Jinping.