We provide a solution to the open problem of bandwidth selection for the nonparametric estimation of potentially non-stationary regressions, a setting in which the popular method of cross-validation has not been justified theoretically. Our procedure is based on minimizing moment conditions involving nonparametric residuals and applies to β-recurrent Markov chains, stationary processes being a special case, as well as nonlinear functions of integrated processes. Local and uniform versions of the criterion are proposed. The selected bandwidths are rate-optimal up to a logarithmic factor, a typical cost of adaptation in other contexts. We further show that the bias induced by (near-) minimax optimality can be removed by virtue of a simple randomized procedure. In a Monte Carlo exercise, we find that our proposed bandwidth selection method, and its subsequent bias correction, fare favorably relative to cross-validation, even in stationary environments.