The control of stresses and liquid pressure surges in pipes is an important problem in the design of hydraulic pipe networks. The method of characteristics has been used to solve the transient stresses and pressures in liquid-filled piping systems. The friction force is included in the equations of motion for the fluid and the pipe wall. The maximum pressure and maximum stress at any point along the length of the pipe are evaluated for the entire simulation time. A nonlinear search technique has been developed using the simplex method. The optimal valve closure is sought, that will minimize the maximum pressure and/or stresses. A continuous optimal valve closure policy is specified using spline functions. Numerical examples are presented showing the reduction of the dynamic pressure and the dynamic stress from linear valve closure to optimal valve closure for a simple pipeline and a complex pipeline. Also, a method for choosing the shortest time of closure which will keep the stresses below specified allowable stresses is presented.