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 equation 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. The Von Mises criterion is used for the stress calculation. 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 stress and the dynamic pressure from linear valve closure to optimal valve closure.