So I came to the US on F1 Student visa on September 2012 and studied for 2 years. I then worked for 3 years in California on F1 OPT. My F1 visa (along with the OPT) got expired in July 2017 after which I returned to India for good. I had income for half of 2017 for which I filed taxes in 2018.
Now in the year 2018, I do not have any ordinary income in the US. I have been investing in stocks for the past few years. The only income I have in 2018 is the capital gains I received from selling the stocks. It is about $26k (long term $13k and short term $13k). So do I have to file tax returns in the US, considering that I was not in the US for the whole 2018 year, except that I visited US as the tourist twice in 2018. Or does it depend on something else?