LAST year Indonesia was struck by the financial storm that pummelled emerging markets, earning itself a place among the so-called “fragile five” of the developing world. When in May the Federal Reserve began discussing plans to scale back its asset purchases, the prospect of higher yields in rich countries made investors reluctant to pour more money into emerging economies. Indonesia’s currency sank in value, along with those of other countries that had been prime destinations for rich-world cash.

This year other emerging markets suffered a similar slump, caused by the Fed’s decision to go ahead with the mooted “taper”. Central banks in Turkey, India and South Africa have all hiked interest rates to defend their battered currencies. Yet Indonesia’s rupiah has rallied by 3.3% against the dollar—the most among major emerging-market currencies. Jakarta’s main stockmarket is trading close to four-month highs. And foreign funds have bought $1 billion more local bonds and shares this year than they have sold.

Indonesia appears to owe its turnaround to timing. It earned its spot among the fragile five thanks to its large current-account deficit, which widened to a record $10 billion, or 4.4% of GDP, last summer. But in August its central bank abandoned efforts to prop up its currency and allowed it to float, leading to a depreciation of about 14% in real, trade-weighted terms from May to now. The weaker rupiah made Indonesia’s exports cheaper in foreign markets and imports more costly. The deficit has since dropped by more than half, to $4 billion, or 2% of GDP, at the end of 2013. In December Indonesia recorded its biggest monthly trade surplus for two years; merchandise exports rose by 10.3% year-on-year (see chart). Other central banks waited too long to respond to market turmoil and then overreacted. Turkey raised rates by 5.5 percentage points in a single day, hoping to cow traders into laying down arms. Bank Indonesia had raised rates earlier, by contrast, and more gradually: enough to cool domestic demand but not enough to touch off a recession. The combination of higher rates and a cheaper currency nurtured a rebalancing. Despite slower consumption growth, annual GDP growth accelerated to 5.7% in the fourth quarter, boosted by exports. Indonesia no longer looks so fragile. Government policy may have helped the process along. The decision to raise the price of subsidised petrol and diesel squeezed demand for oil, which accounted for about 23% of imports at a cost of $42 billion last year. Other measures look less effective, like higher taxes on imports of some consumer and luxury goods. But the government, heady with recent success, now risks scaring away investors with heavier-handed intervention. On February 11th Indonesia’s parliament passed a new trade law giving authorities far-reaching powers to restrict exports and imports. Its dubious aim is to protect local producers from foreign competition while developing higher-value industries. Bayu Krisnamurthi, the deputy trade minister, bragged that it showed that Indonesia was “not adopting a free market”. The law is only the latest in a series of ill-considered trade policies, which includes a recent ban on exports of mineral ores that puts at risk some $5 billion a year in foreign-exchange receipts.

The turn toward protectionism is linked to this year’s parliamentary and presidential elections—laissez-faire economics is unpopular in Indonesia. Yet with global capital in a fickle mood, governments cannot assume that markets will shrug off electioneering. Indonesia owes the striking turn of fortunes in its economic performance to rather orthodox economic policies. The central bank let market forces operate freely, allowing the rupiah to depreciate to the point where exports have become competitive again. If the authorities continue on their protectionist course they may convince investors that Indonesia remains fragile after all. And pushing the economy back into financial turmoil is unlikely to be a vote-winner.