To understand how, you need to understand 'put options', which is a financial product available on the derivatives market. A put option is a deal to sell company stock at a pre-agreed price. Worth noting that you don't need company stock before the put option deal is reached.
So let's say the stock price of Company X is currently valued at $50, and you arrange a put option to sell stock at $50. If the stock price goes down, let's say to $25, you buy stock at $25 and sell it at $50, so you've made a profit (from what I understand, you don't even need to buy the stock in this case, the put option broker will just pay you the difference to simplify the process).
But what if the stock price rises? Let's say the stock price rises to $75. You can't buy stock and use your put option without losing money, and from what I understand you pay interest to the put option broker for the length of time you have it, so holding onto the put option causes you to lose money.
But there's a 'get out of jail free' option. When you arrange the put option you also buy stock. If the stock price goes down, you buy more stock and sell at the pre-agreed put option price. If the stock price goes up, the stock you hold is worth more and you can use this to clear the put option without losing money.
From what I understand, this is one example of 'hedging' against stock price changes, there are probably others. HFT is well suited to this kind of deal, as you can react quickly to market changes, minimising any risks resulting from delays.
So although people see the stock market as gambling, you can game the system to move the odds in your favour. The end result is huge volumes of money invested into non-productive uses of money (and because of the ways banks create money, and the ways the financial markets are regulated, the restrictions on this speculation is basically non-existent).
EDIT: I've got a downvote on this already. If anything I've said is untrue, then call me out on it.