If dollars were being repatriated, but as investment into financial instruments and real estate instead of purchases of goods and services, then that would not affect the trade deficit, right?

I don't believe so. I don't think foreign equity and real estate purchases are counted in trade balance. Those assets never leave the US as exports.