A good initial guess and an appropriate homotopy equation are two main factors in applications of the homotopy perturbation method. For a nonlinear oscillator, a cosine function is used in an initial guess. This article recommends a general approach to construction of the initial guess and the homotopy equation. Duffing oscillator is adopted as an example to elucidate the effectiveness of the method