In this paper we consider a method of solving optimal stopping problems in discrete and continuous time based on their dual representation. A novel and generic simulation-based optimization algorithm not involving nested simulations is proposed and studied. The algorithm involves the optimization of a genuinely penalized dual objective functional over a class of adapted martingales. We prove the convergence of the proposed algorithm and demonstrate its efficiency for optimal stopping problems arising in option pricing.