After hours of painstaking research, arguing with yourself, and looking at charts, it's finally time to pull the trigger and buy the stock. You log into your account. You enter the stock symbol and the price you're willing to pay.

But there's one more thing -- how many shares should you buy?

If you're like a lot of investors, most of your time is spent choosing the best stocks to buy. Then, when it is time to decide how many shares or contracts to purchase, you go with your gut.

Even seasoned investors sometimes do this. They make impulsive, emotional decisions. Behavioral finance is a field that studies why people do what they do when it comes to money. It says our financial decisions are often rooted in instincts. Instincts helped our hunter-gatherer ancestors, but they can hurt our investments. We've written a free report about the instincts that can get in the way of investing: it's available here.

The most successful investors limit the role that emotions play in their decisions. One of the ways they do this is by deciding on the best position sizes for their portfolio. And they do this before they place the order to buy.

If you buy too much of a stock and it falls in value, you might start suffering from loss aversion. No one likes losing money. It has been proven that the pain of losing is a stronger feeling than the joy of winning.

So, when we think we might lose money, or even when an investment starts falling in value, we naturally get worried. That might cause us to sell an investment too soon.

On the other hand, if we didn't buy enough of a position to start with, we'll also regret it when the share price starts to climb. That can cause us to buy more than we should as we chase the price higher.

But when we have the right position size it's easier for us to relax. We can sit back and enjoy the results of our hard work and careful planning.

It's like if you have $100,000 to invest and you purchase $25,000 of stock XYZ. How would you feel if the stock drops 10%? That is $2,500 dollars, or 2.5% of your portfolio gone. It could sting a little, but if you've already decided you can live with it you'll be fine.

But what if you felt great about that stock and invest all your money in it on a whim. That same 10% drop now equals $10,000 dollars. That sort of loss can lead to irrational, emotional decisions. Like dumping the shares of an otherwise good long-term investment. Or, holding on to the shares of a dud of a stock.

To avoid this stress, think before deciding how much to buy. The amount to buy should depend, not on how much we want to make, but on how much we can handle losing.

The first step is to decide on your stop-loss level. A stop-loss sets a limit on how much you are prepared to lose on a stock. If your stock hits that price, you would automatically sell the shares to avoid any further losses.

For example, you could decide that your threshold for a $20 stock is if it drops below $17 per share. So, you set your stop-loss at $17.

The next step is to think about how much of a paper loss you can tolerate. Let's say with an account of $100,000, you don't want to lose more than $2,000.

You then divide this $2,000 by the $3 per share loss ($20 - $17 stop-loss price). The result will be your position size, or the number of shares to buy. In this example, that's 667 shares.

Here is a formula and table to illustrate:

(Maximum $ Risk)/ (Current Stock Price - Stop Price) = Position Size

Image placeholder title

Knowing how many shares to buy is key to a well-thought out investment plan. It's as important as picking the right stock.

Kim Iskyan is the founder of Truewealth Publishing, an independent investment research company based in Singapore. Click here to sign up to receive the Truewealth Asian Investment Daily in your inbox every day, for free.

This article is commentary by an independent contributor. At the time of publication, the author held no positions in the stocks mentioned.