The deadline to turn those investment dogs into tax savings is coming up.

It’s a strategy called tax-loss selling. If you trigger a capital loss on a stock before the end of 2018, it can be used to recover tax paid on capital gains going back three years, or it can be banked up and used to offset future capital gains.

Tax-loss selling only applies to securities in non-registered accounts since capital gains are not directly taxed in registered retirement savings plans (RRSP) or tax free savings accounts (TFSA). However, if you sell a stock from a non-registered account for tax-loss purposes, you can generate further tax savings by putting the cash in a registered account. In the case of an RRSP. the contribution can be deducted from your taxable income whenever you wish and it will not be taxed until it is withdrawn in retirement.

If the funds are invested in a TFSA, gains on the investment are never taxed.

If you’re looking for a tax-saving hat trick, contribute the cash from a tax-loss sale to an RRSP and contribute the RRSP refund to your TFSA.

If you feel your stock is down but not out, you can even purchase it back at least 30 days after the sale.