Can I use carryover loss in 2017 to offset the capital gain in 2018 when I file as dual status?

I left US in 2018 Feb and filing as part year resident and non-resident for 2018. For capital gain in 2018, can I use carryover loss in 2017 to offset the gain when I file as dual status? Thank you in advance.