The critical point is that capital gains are not taxable in the U.S. if the nonresident alien does not spend more than 183 days per year in the U.S. Most active traders don’t generate significant dividend income paid by U.S. companies, so tax withholding is not a problem. Many of them get a foreign tax credit for U.S. tax withholding in their resident country.
Sell the U.S. stocks before you die, and don't stay in the U.S. for more than 183 days that year.
https://www.forbes.com/sites/greats.../how-to-save-u-s-taxes-for-nonresident-aliens
May not work in many cases. Get killed in accident. Or suddenly die in heart attack without warning.
Nobody can know in advance when he is going to die. Maybe cancer patients who have been forewarned by doctor but in many cases, we won't know.
Nothing is certain except death and taxes.
--Benjamin Franklin
