If you borrow money to invest you are allowed to deduct the interest on the loan. You have to keep the money invested in order to keep taking the tax deductions for the loan. If you sell the investments, then you cannot continue to deduct the loan interest. This seems fair.
If you have sold investments and used the money for something else, you may not realize that you have lost the deduction for the interest on that loan. Pay attention to the amount that you have invested compared to the principal amount that you have borrowed. You have to show that your investments are more than the amount you borrowed in order to continue to claim the interest. Just having an investment loan will not be enough to get the deduction, you have to be able to show that the proceeds of the loan are still invested.