Definition
A limit order instructs a broker to buy at or below, or sell at or above, a specified price. It controls the worst price you will accept but does not guarantee that the order will be filled.
How it works
A buy limit placed below the current ask waits in the order book until sellers come down to that price; a sell limit placed above the current bid waits for buyers to come up. A limit that crosses the spread is marketable and executes immediately against resting orders, at the limit price or better.
Resting limit orders are usually queued by price and then by time, so a market can trade at your price without filling you if others are ahead. Orders can also fill only partly, leaving an unfilled remainder.
Formula / convention
Buy limit: fills only at the limit price or lower; sell limit: fills only at the limit price or higher
Illustrative example
Illustrative: a fictional share has a bid of HK$49.90 and an ask of HK$50.10, and you enter a buy limit for 300 shares at HK$49.95. Nothing fills until a seller accepts HK$49.95 or lower. If 200 shares trade at HK$49.95 and the price then rises away, you hold 200 shares costing 200 × 49.95 = HK$9,990, and 100 shares remain unfilled.
What to watch for
A limit order protects the price but may leave you with no trade at all if the market moves away. It does not protect an existing position from loss, and a good-till-cancelled order can fill days later under conditions you no longer intended.