Yes, but there are limits. Losses on your
investments are first used to offset capital gains of
the same type. So short-term losses are first deducted
against short-term gains, and long-term
losses are deducted against long-term gains.
Net losses of either type can then be
deducted against the other kind of gain.
For additional information please see this TurboTax article, Capital Gains and Losses, which has been updated for Tax Year 2017.
**Mark the post that answers your question by clicking on "Mark as Best Answer"
Generally, the capital loss on the sale of the stock can be used to offset the capital gain on the sale of the property. Generally, you can offsets capital gains with capital losses from any sources.
It's not easy to lose $500,000 on stock in less than a year.