Often times you hear about the importance of setting a stop-loss before opening trades. But if you are a quant, I assume you already know the importance of it.

You may use stop-loss for two reasons:

  1. Setting your stop-loss at the beginning of opening a trade
  2. Exiting your open positions with (some kind of) trailing stop

_Note #1: _A stop order can be used for opening trades too, which is an advanced usage of a stop order. I will not be talking about that in this tutorial.

Note #2: As in all my tutorials, I’ll be using the Python language and the JesseAI framework. Both are open-source and free to get started.

Whether your strategy uses (some kind of) a trailing stop to exit or it exits at a specific price, it doesn’t matter for now. But the idea of setting a stop-loss below your entry price is just non-negotiable. In my opinion, your strategies are flawed if they don’t use it.

Why is the exact stop-loss price so crucial?

Let’s say you decide to use a stop-loss. But what would be your exact stop price? Does it really matter? Yes! It is crucial actually.

While increasing the margin of your stop-loss will increase the win-rate of your strategy, it will reduce the size of your position. Smaller positions sizes mean smaller profit in the long term. And of course, long-term profit is what algo-trading is all about.

I’ll explain this with an example:

Image your total capital is 10,000 and you intend to risk 3% of it per trade.

Let’s say your strategies tell you to enter the market at $100, and to set your stop-loss at $80 (in this article I’m covering ways to determine the exact price). How much should the size of your position be?

Since talk is cheap, I’m gonna answer with the code:

entry_price = 100
	stop_price = 80
	risk_percentage = 0.03
	capital_size = 10000
	risk_per_qty = 100 - 80 # 20

	position_size = ((risk_percentage * capital_size) / risk_per_qty) * entry_price

	position_qty = position_size / entry_price # 15

Thus the position quantity should be 15 so that I only risk 3% of my capital which is $300.

Now let’s see what will happen if I tighten my stop-loss and still risk 3% ($300). Let’s say I put my stop loss at $90 instead:

entry_price = 100
	stop_price = 90
	risk_percentage = 0.03
	capital_size = 10000
	risk_per_qty = 100 - 90 # 10

	position_size = ((risk_percentage * capital_size) / risk_per_qty) * entry_price

	position_qty = position_size / entry_price # 30

Note that I’m still risking $300 per each trade but my position size is doubled, and so is the possible profit (if it turns to be a profitable trade). But of course, a tighter stop-loss means you’ll get stopped out of your trades more often which means the win-rate will be reduced.

You want your stop-loss not be too tight, neither too loose.

I have created a small website that lets you play with this formula to fully understand how position sizing works.

Now I want you to talk about 4 ways that I use to determine the exact stop-loss in my algo strategies.

#data-science #trading #cryptocurrency #bitcoin #python

4 Practical Methods to Set your Stop-Loss When Algo-Trading Bitcoin
2.30 GEEK