During the past few weeks, the major stock indices have lost close to 10% of their value. And some companies and entire sectors have done much worse than that.

^SPX Chart

When the market gets like this, the decisions you make can have an enormous impact on your financial future. Specifically, there's one thing you definitely don't want to do: sell.

Many investors are counterproductive
The most basic principle of investing is to buy low and sell high. This is easy enough to understand; but sometimes, our instincts work against us.

When the market sells off, like it has over the past couple of weeks, our instinct can be to get out before our stocks drop further. And when things keep going up, up, and up, like they did the first half of this year, our instincts tell us to throw more money in and take advantage of the upward momentum.

However, this is the exact opposite of how you should be investing. The absolute worst thing you can do when stocks are falling is to panic and sell. Instead, you should look at it as an opportunity to get into your favorite stocks at a discount.

Take a look at the 2008-2009 financial crisis, when the market was selling off with no bottom in sight. If, instead of panicking, you decided to pick up some cheap shares of great businesses, you could have purchased shares of Wells Fargo for about $8 (now worth about $48), Microsoft for $15 (now around $43), and Caterpillar for $22 (now $93).

These are just a few examples, but I use them because they are all companies that even during the darkest hours of the financial crisis obviously weren't going anywhere. Anyone who remained calm during the crisis, and saw the value in businesses like these, had an opportunity to make a lot of money.

Learn from the master
No one is better at buying good companies cheaply than Warren Buffett. And he's been buying stocks during the latest sell-off.

In fact, Buffett loves when the market goes down. In a recent interview with CNBC, Buffett said, "The more [the market] goes down, the more I like to buy." He really doesn't worry about the reasons the market is dropping, as long as they don't have much to do with the companies themselves.

He said he buys businesses that are going to be around for another 50 years, and this is the reason he doesn't really care about trying to time the market, or when the Fed is going to raise interest rates. Over the long term, such events really don't matter too much.

In fact, during the financial crisis, Buffett made some of his savviest moves ever. Between the years 2008 and 2011, he made investments in blue chip companies such as Goldman Sachs, Bank of America, Mars, General Electric, and Dow Chemical totaling about $25 billion. And the Wall Street Journal estimates Buffett's profits from those deals to have reached about $10 billion by last October, a 40% return in just a few years.

Good performance in a bad market is one of the best things you can do
Continuing with the Warren Buffett wisdom, one of the most important things to your long-term success is doing well when the market is doing poorly. Buffett's Berkshire Hathaway doesn't always outperform the market. In fact, the company has underperformed the S&P 500 for four of the past five years. Buffett even said in his latest letter to shareholders that he expects to fall short in years when the market is strong. However, the S&P 500 has had 11 negative years out of the last 50, and Berkshire has outperformed the index in every single one.

One of the most surefire ways to kill your long-term investment performance is to sell your shares as soon as they become cheap, so don't do it. Instead, by looking at market sell-offs like this one as buying opportunities, you are setting yourself up to own great companies at low prices -- which will always win over the long run.