In the power systems with high-voltage DC (HVDC) transmission, the angular oscillations among the synchronous generators (SGs) endanger the system security. The pre-fault power of the HVDC changes the power flow and affects the system dynamics, hence may be optimized to improve the system stability. However, the HVDC power does not appear in the system matrix, thus it is difficult to derive the analytical expression of the trajectory sensitivity (TS) for parameter optimization. Based on the power flow equations, the initial value of the TS is newly introduced in the sensitivities of the power angles of the SGs with respect to the intermediate variables and then to the DC powers. The imbalanced matrix of the TS is derived during the time-domain simulation. By setting the objective function as the integral of the square of the relative value of the SGs' power angle deviation with time, and summing the trajectory sensitivity for all time steps, the gradient information of the objective function to the DC powers is newly derived. The optimization model is solved with the interior point method to adjust the steady-state HVDC powers. The effect of the power optimization on the angular oscillation is verified with the time-domain simulation. The numerical results show that the objective function is reduced by 37.92%, and the oscillation amplitude is reduced by 35%.