No one has figured out a way to do this without outside information. Some blockchains include price feeds from the outside world that let algorithms keep prices relatively stable. Others use votes by currency holders to adjust the money supply both directly and indirectly (via interest rates) like a central bank would. Both strategies have led to cryptocurrencies that track the price of the dollar.