The technical glitch that shut down the New York Stock Exchange this week wasn’t the first issue of its kind to hit the markets, and it won’t be the last.

Thankfully investors were able to resume trades on other exchanges while they waited for the NYSE to reopen. But some technical glitches have the potential to disrupt markets. (Remember the Flash Crash?) Truth is there is no telling when or why stocks might tank. Bad economic news or a natural disaster or a disappointing earnings report could send investors running to pull money from the market.

But people can protect their portfolios from sudden movements — including daily market swings — by setting limits within their portfolio that restrict how much they’re willing to pay for an investment and how long they want to keep a holding that is on the way down.

One of the most widely used tools available to traders is an option called a limit order. Investors can use the orders when buying a stock or exchange-traded fund to cap how much they’re willing to pay for that share.

“You are trying to give yourself control over the price of which you want to buy,” says Jim Rowley, senior investment analyst with Vanguard.

Say an investor wants to buy a stock that is trading at $25. A regular purchase order would cause the investor to buy that stock even if it suddenly soared to $30 while the trade is in process. With a limit order, the investor could make it so they won’t pay more than $26 for that stock. Of course, using the measure also means that the trade might not go through.

“The risk is that you won’t get the stock at all,” says Dave Whitmore, senior strategist for investor education at E*Trade Financial.

Limit orders can also help investors who are trying to sell off a stock or ETF at a specific price but are worried about volatility, Rowley says. If the share price falls below the level set by the limit order, the sale won’t go through.

Imagine an investor who bought that hypothetical stock at $25 a share, but doesn’t want to sell for it for less than $24. The risk in this scenario is that a person ends up holding on to a stock that’s sinking in price. But it may also help an investor hold on to the stock until prices rebound, preventing them from locking in big losses if the stock price drops suddenly during the sale. 

Traders who want to dump a stock before it loses too much value might want to use what’s called a put option instead. The option works as a form of insurance against a stock that is falling in price, Whitmore says. Say an investor buys a stock at $25 but doesn’t want to lose more than $5. He can buy a put option that would trigger a sale if the price fell below $20, Whitmore says.

The final sale price might be a little lower than $20, depending on what exact price the stock has when the sale is executed, he says. But the measure can still help to minimize the downside for investors worried about losses.

Of course, there is no way to eliminate risk when it comes to investing, financial advisers say. Long-term investors should worry less about technical trading tools and focus more on making sure their portfolios are diversified, which would make them less vulnerable to the move of any one stock or investment fund, Whitmore says.

Read More: