People sometimes ask me if there is a guaranteed way to help them avoid losing money in the stock market. The truth of the matter is that the only time you ever really lose money in the stock market is when you sell a position at a loss. For example, pretend you bought a stock at $10 per share. The stock goes down to $6 dollars per share. You decide to sell. At that moment, you lose money. Just because the stock goes down doesn't mean that you have actually lost anything -- remember, you only lose money when you sell the stock.
One strategy that advanced investors utilize to mitigate against the risk of loss is to sell in-the-money call options at the same time they purchase a particular stock. This process helps to give them a little bit of wiggle room should the stock go down. Remember, since you only lose money if you sell off a position at a loss, the money that you have collected from selling the call option allows you to essentially sell a stock that you bought at a particular price for a lower price as long as the price difference is made up by the call option premium that was collected.
This is just one example of an advanced trading strategy that can sometimes be used to hedge one's investments. Unfortunately, the only real way to ensure you never take a loss in the stock market is to simply never sell a stock that has gone down a lot in price.