Buying power is incorrect

If you buy 5000 shares, sell 4000 shares, C2 still use 5000 shares to calculate buying power instead of 1000 shares. Even after I sell 1000 shares, the buying power is incorrect.

I don’t think it is a compliated algorithm, don’t know why C2 can not handle it.

Please check the buying power of my system.