Is it allowed to open account in stock market and earn money by buying and selling shares? Or is it considered gambling?

No problem, provided that the shares are of companies do not deal in haram goods, such as Alcohol, non halal meat, Banks.