If you invested in stocks anytime in the past year and a half, the past couple of months have probably brought you some nice gains. But if the market's stratospheric rise has you wondering whether you should take profits, don't be too quick to hit the sell button. By taking advantage of a simple ETF strategy, you can protect your gains without triggering a big tax bill.

Protecting yourself
Deciding whether to take profits is always a tough call. If you sell your shares,  you avoid the risk of riding the next Enron or Lehman Brothers down to zero. But you also miss out on future gains, potentially creating the sort of nightmare scenario that still makes investors in companies from Microsoft in the 1990s to Netflix today cringe.

Today's environment is especially difficult because of the blistering speed at which many stocks have risen. In just the past four weeks, F5 Networks (Nasdaq: FFIV), rare-earth phenom Molycorp (NYSE: MCP), and Keurig king Green Mountain Coffee Roasters (Nasdaq: GMCR) have all soared 25% or more. When prices rise so quickly in such a short period of time, stocks can get ahead of themselves -- and even long-term investors may want to take a look at hedging their gains against a pullback.

Hello, tax man
But selling after a quick gain means you'll pay short-term capital gains taxes on your profits. If you don't hold a stock for longer than a year, the 15% maximum rate on long-term gains doesn't apply, and you can be on the hook for as much as 35% in federal taxes. Add in state income tax if applicable, and you can see that there's a hefty price for locking in your profits.

But with the help of ETFs, you may be able to protect yourself at least somewhat from a reversal of fortune in your stocks. You won't get a perfect match, but often, what pushes your stock down will also affect the entire industry, making a sector ETF a good hedge against risk.

The mechanics
Here's how it works: Find an ETF that corresponds to the stock whose gains you want to protect. Then sell shares of the ETF short, determining the appropriate amount to sell based on the value of your stock holdings and whether you want a total or partial hedge.

For instance, consider F5. As a networking firm, it competes with companies like Cisco (Nasdaq: CSCO) and Juniper Networks (NYSE: JNPR), but many of the macroeconomic trends that affect their stock prices are the same. As it happens, the iShares North American Technology Multimedia Networking ETF (NYSE: IGN) owns shares of these and other entrants in the networking space.

Even though the iShares ETF owns shares of F5, you can sell it short without triggering gain on your own F5 shares. Now of course, if some company-specific piece of news hits F5, the ETF won't lose as much because its position in F5 stock is relatively small. But if some outside competitor gives the whole industry problems, then the ETF might well track F5 shares much more closely.

Similarly, you could use the new Market Vectors Rare Earth Metals ETF (NYSE: REMX) to hedge Molycorp shares, in which the ETF has roughly 5% of its assets. For Green Mountain, there's no coffee retailer ETF -- at least not yet -- but you could use a fund like First Trust Consumer Staples (FXG), which has 4% of its assets in the stock.

When the time comes to take off the hedge, just buy back the ETF shares. You'll have a gain or loss on that trade, but that may pale in comparison with the gains you would've realized on the stocks you own.

Keep more money for yourself
Earning a profit on an investment is great, but even better is getting to keep as much of that profit as you possibly can out of the hands of the IRS. By strategically using ETFs and short selling to hedge against reversals, you can take a big step toward protecting your gains from whatever the future may bring.

ETFs aren't just for hedging -- you can also make some serious money with them. Click here to read The Motley Fool's free report, 3 ETFs Set to Soar During the Recovery.