Yes, you can invest in the stock market with an F-1 status. However, there are a few things to keep in mind:
1) It can't be active trading. It's up to interpretation what exactly that means. In my opinion if you are not constantly trading and trying to make trading a big part of your income, you should be fine. A good example is a 401(k), you're investing but not actively trading and saving all profits for retirement.
2) Be aware that several companies won't open an investment account for someone that is not an Lawful Permanent Resident or a US Citizen. That's because they have some extra compliance requirements. If you find one that welcomes you, make sure to let them know your status. Last thing that you want is paper work filled incorrectly claiming that your are a USC (that's a life ban from the US).