A valve for closing fluid communication between a well (W) and a production string (PS) when a content of an undesired fluid in a fluid flow exceeds a predetermined level, the valve comprising: - a flow barrier ; - a primary flow channel having a primary inlet through the flow barrier , a low pressure portion , and an expansion section (5"); - a secondary flow channel having a secondary inlet through the flow barrier and a secondary outlet connected to the primary flow channel at the low pressure portion of the primary flow channel , wherein a diameter of the secondary inlet is larger than a diameter of the secondary outlet such that a hydraulic resistance of the secondary outlet is larger than the hydraulic resistance of the secondary inlet ; - a chamber forming part of the secondary flow channel ; - an inflow control element , the inflow control element being a flotation element movable in a path arranged at an upstream side of the flow barrier , wherein the path extends between a first position and a second position for closing the secondary inlet when the inflow control element moves to the second position due to the undesired fluid in the flow upstream of the flow barrier exceeding the predetermined level; - a valve seat ; and - a piston having a first piston portion exposed to the secondary flow channel in the chamber and a second piston portion exposed to the primary flow channel downstream of the expansion section (5") so that the piston is movable by a pressure differential between the first piston portion and the second piston portion , the piston being movable between a first piston position and a second piston position; and wherein the piston is operatively connected to the valve seat so that the primary flow channel is closable when the piston is in the second piston position. - a flow barrier ; - a primary flow channel having a primary inlet through the flow barrier , a low pressure portion , and an expansion section (5"); - a secondary flow channel having a secondary inlet through the flow barrier and a secondary outlet connected to the primary flow channel at the low pressure portion of the primary flow channel , wherein a diameter of the secondary inlet is larger than a diameter of the secondary outlet such that a hydraulic resistance of the secondary outlet is larger than the hydraulic resistance of the secondary inlet ; - a chamber forming part of the secondary flow channel ; - an inflow control element , the inflow control element being a flotation element movable in a path arranged at an upstream side of the flow barrier , wherein the path extends between a first position and a second position for closing the secondary inlet when the inflow control element moves to the second position due to the undesired fluid in the flow upstream of the flow barrier exceeding the predetermined level; - a valve seat ; and - a piston having a first piston portion exposed to the secondary flow channel in the chamber and a second piston portion exposed to the primary flow channel downstream of the expansion section (5") so that the piston is movable by a pressure differential between the first piston portion and the second piston portion , the piston being movable between a first piston position and a second piston position; and <EOS>