If you're working in ArcGIS this should be pretty straight forward. You need to do a select (Select Layer by Attributes) on your other feature layer to select all the 'closed' valves. You then pass in that layer to your barriers parameter on the Trace tool. The tool should honor and use only the selected features.
I would first Generalize the lines to reduce the vertices to work with and the try Snap or Integrate to capture nearby A Network features. Finally, Select by Location or Spatial Join may be used to get A Network features.