Hello, if you have a fair amount of margin debt, and then sell shares to almost bring the margin balance to zero. Will you then pay capital gains on the sale? Or will it cancel out since it was margin debt? Thank you

Hello, if you have a fair amount of margin debt, and then sell shares to almost bring the margin balance to zero. Will you then pay capital gains on the sale? Or will it cancel out since it was margin debt? Thank you