Knowing when to buy a stock can be tough, but knowing when to sell can be even tougher.

Most investors know the feeling of selling a share, only to watch it rally higher in the weeks and months that follow. That feeling of missed opportunity can feel even worse than losing money!

Of course, it’s impossible to tell with any certainty when a company’s share price will peak, leaving it up to luck to determine whether you sell out just at the right time, or else right before it climbs higher.

So, when exactly should you look at selling a stock?

The answer to that question really depends on your circumstances, and the company’s shares in question. Outlined below are some factors you should consider before selling any stock. Unfortunately, they won’t make it any more likely you’ll sell out at the right time, but they should at least guide your thinking before making a mistake.

1. Has the rise in price been justified?

Selling a stock simply because it has recorded a 10%, 20%, or even a 100% gain to lock in profits could prove to be a very bad move. You may have heard the adage ‘let your winners run’. If the company you’ve invested in has gone from strength to strength, the run-up in its share price could be more than justified, and could signal even more gains to come.

Biopharmaceutical giant CSL Limited (ASX: CSL) is a great example. Early in 2012, the shares were trading for $32 before gaining 70% to around $54.40 a year later. Had you sold, you would have missed out on another strong run in price as they are fetching almost $107 per share today.

CSL is by no means the only example. Consider Bellamy’s Australia Ltd (ASX: BAL) whose share price exploded in 2015. Or Commonwealth Bank of Australia (ASX: CBA) which has generated enormous returns for investors over the last two decades.

2. Would you buy today (if you didn’t already own it)?

One question I ask myself before selling shares in a business is whether I would consider buying some today if I did not already own them? If the answer is ‘Yes’, then it’s probably not worth selling just yet – even if it is to ‘lock in a profit’.

3. Know your thesis

Understanding the companies you invest in can protect you from selling out too early to lock in profits. If your original investment thesis changes (for instance, the company makes a risky acquisition or a number of key personnel leave the business unexpectedly) it could be time to sell. If the thesis remains intact, however, that’s often a good reason to remain patient and invested.

4. What will be the tax consequences?

Selling out of a profitable investment not only creates a new brokerage charge, but also a capital gain. Thus, you should consider your tax responsibilities before selling any investment.

5. Are there better opportunities?

Sometimes, a company’s share price can outrun its potential. If the market offers you a price that is simply too good to ignore, it could be worth taking your money off the table and investing it in other great opportunities. In doing this, however, you should question your reasons for thinking there are better opportunities, and also consider the potential tax charges you’re likely to incur for selling.

6. Are you holding out for a rebound?

When a stock you own falls sharply in price because of poor performance, investors can sometimes be tempted to ‘water their weeds’. In other words, they look to buy more shares at a lower price in order to reduce their average buy price, despite the fact the company’s performance isn’t up to scratch. This could be a good time to sell.

7. Are you selling just because the share price has fallen?

While some investors will ‘water their weeds’, others can tend to panic as soon as their shares fall in price. In this situation, it is important to consider two things. First, ask yourself the same question as above: would you buy the shares today, if you didn’t already own them? That is, if you didn’t own the shares, would you consider the stock to be a good buy as a result of its drop in price? Second, revisit your thesis: if the company’s fundamentals remain intact and the price is simply being driven lower by a bit of noise in the market, you should think twice before selling.

As you can see, there are a number of factors that should be considered before you sell your shares. Selling out too early, or for the wrong reasons, can prove very costly in the long run.

That said, sometimes selling is necessary, whereby holding on for too long could be poison for your portfolio. Click here now to get a full rundown on three ASX shares our top analysts think could be a sell today. Do you own any of them?

HOT OFF THE PRESSES: Motley Fool’s #1 Dividend Pick for 2017!

With its shares up 155% in just the last five years, this ‘under the radar’ consumer favourite is both a hot growth stock AND our expert’s #1 dividend pick for 2017. Now we’re pulling back the curtain for you... And all you have to do to discover the name, code and a full analysis is enter your email below!

Simply enter your email now to receive your copy of our brand-new FREE report, “The Motley Fool’s Top Dividend Stock for 2017.”

By clicking this button, you agree to our Terms of Service and Privacy Policy. We will use your email address only to keep you informed about updates to our website and about other products and services we think might interest you. You can unsubscribe from Take Stock at anytime. Please refer to our https://www.fool.com.au/financial-services-guide">Financial Services Guide (FSG) for more information.

Motley Fool contributor Ryan Newman owns shares of Bellamy's Australia. The Motley Fool Australia owns shares of Bellamy's Australia. We Fools may not all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors. The Motley Fool has a disclosure policy. This article contains general investment advice only (under AFSL 400691). Authorised by Bruce Jackson.