Abstract Finding the most suitable closing law is essential to decrease the shock wave pressure caused by transient flow and minimize the potential damage to equipment. The closure of a valve can occur instantly, rapidly, or gradually, and the appropriate law can be convex, linear, or concave, depending on various factors. These factors include the pipe's characteristics (type, diameter, roughness, and length), the conveyed fluid (nature and temperature), and operating conditions (pressure and flow rate). Other factors that receive less attention, such as the duration of slow closure and the impact of soil load on the pipe, are also considered in this study. The main focus of this article is to investigate how the optimal law evolves based on the time it takes for a valve to gradually close, specifically in the case of a valve located at the end of an underground gravity supply pipe. The findings reveal that when the slow closure time (t) exceeds 0.50 times the return period (t4), the exponent of the optimal law becomes a damped periodic function. Each closure time corresponds to a unique optimal law, and as the valve closure time increases, the range of optimal laws becomes narrower.