If you sell your investments with unrealized gains in the same year you sell investments with unrealized losses, they will offset each other. If your gains exceed your losses, the net amount will be taxable in the year your sell. If your net losses exceed your gains you can take up to a $3,000 loss which will offset ordinary income that year. Any remaining losses can be carried forward to offset future gains or up $3,000 of ordinary income per year.