When you place trading orders with your broker, you have more options than just barking "buy!" or "sell!" There are lots of orders that can accomplish lots of things.
For example, if you bought a stock at $20 that is now trading at $50 and you want to sell it if it drops to $40 (locking in a 100% gain), there's a certain kind of order you may want to place -- either a "stop-loss" or "stop-limit" order. The "stop" activates the order if shares sink to a certain price ($40 in your example). The stop-loss order immediately sells the shares at the best price it can, while the stop-limit will sell only if the shares are at $40 or above.
Here are the risks: If, perhaps because of bad news, the shares suddenly fall below $40 overnight and don't rise above that, the stop-loss will sell your shares for less than $40, while the stop-limit order won't sell the shares at all.
This article offers greater detail on these and other orders you can place with your brokerage. There's the market order, for example, which executes at the best available current price.
To learn to more about brokerages and possibly find a better brokerage for yourself, check out our Broker Center.