What happens when your tax agreement expires is that IB withholds, in my case, 30% of the settled price.
They don't withhold 30 % of the capital gain, even thought they are aware of your gain/loss, but they withhold a percentage of the settled price whether you have a gain or a loss.