This paper studies the performance of time-varying capital controls on crossborder bank borrowing in an open-economy, dynamic stochastic general equilibrium model with credit market frictions and imperfect capital mobility. The model is parameterized for a middle-income country and is shown to replicate the stylized facts associated with a fall in world interest rates (capital inflows, real appreciation, credit boom, asset price pressures, and output expansion). A capital controls rule, which is fundamentally macroprudential in nature, is defined in terms of either changes in bank foreign borrowing or cyclical output. An optimal, welfare-maximizing rule is established numerically. In addition, the optimal simple rule is shown to perform well relative to the Ramsey policy. The analysis is then extended to solve jointly for optimal countercyclical reserve requirements and capital controls rules. The results show that a more aggressive credit-based reserve requirement rule induces less reliance on capital controls. Thus, countercyclical reserve requirements and capital controls are partial substitutes in maximizing welfare.