We have recently added Trailing stop loss (TSL) and in this post, we will discuss how to use this feature.

Trailing Stop Loss allows traders to manage their risk better as it modifies the Stop Loss set when the price moves in their favor. Let us understand this with an example.

Once a strategy is deployed, Streak monitors the instruments you have deployed the strategies on and sends an actionable notification as soon as the entry condition is met. Once the user acts on the notification, the order is sent to the exchange via your broker.

The order once executed at the exchange, the Stop Loss (SL) and Target Profit (TP) are monitored by Streak.

Note: The SL and TP are based on the Entry price at which the Exchange executes orders.

Case 1: Without TSL

When you are creating any strategy in Streak, it is mandatory to set a Stop Loss and a Target Profit. So here in this example

My Entry Price: 100
Position type: Long

SL: 10
TP: 20

So after I enter a long position at 100,
SL price: 90
TP price:120

Now, only 3 things can happen.

a. if the price rallies up to 120 or higher, my TP will be triggered
b. if the price does not move and consolidates, neither the SL nor the TP will trigger
c. if the price drops to 90 or lower, my SL will be triggered

Case 2: With TSL

Now, lets us look into what happens when we add a TSL. If you add a TSL and the stock moves in your favor by a particular number of points, the Stop Loss will move closer to my Entry Price by the same number of points.

Example:

My Entry Price: 100
Position Type: Long
SL: 10
TP: 20
TSL: 5

Now when you enter the trade, the above scenarios(a and b) are still applicable. However, if the price move in your favor i.e if you enter a long position, and the stock price moves up, the TSL will act as a qualifier and an increment and your initial SL will also move up.

So after I enter a long position at 100,
Initial SL price: 90
TP price:120

a. if the price drops to 90 or lower, my SL will be triggered
b. if the price does not move, neither the SL nor the TP will trigger
c. 1. if the price rallies up to 105.1 i.e a 5 point increase, my SL will revise to 95
2. if the price rallies up to 107.5 i.e a 7.5 point increase, my SL will revise to 95
3. if the price rallies up to 116 i.e a 16 point increase, my SL will revise to 105

Note: the price has to move up by the number of points specified in TSL to trigger the SL change.

After the SL is revised, if the stock price fall, your SL exit will be triggered at the new SL price. So if the stock rallies up to 116 and then later falls to 105, my SL will get triggered and an actionable notification will be sent. So with TSL, Streak keeps on tracking and updating the SL automatically from the backend as the price moves in your favor and as a result, you will get out of the trade with some profit(5 point profit in this example).

TSL flow in the Live market

The TSL type will be as per the TPSL type set. Therefore, if in the above scenario, the TPSL type set is a percentage, the TSL will also be trailed in percentage.

My Entry Price: 1000
Position Type: Long
SL: 5%
TP: 10%
TSL: 2%

Entry: Long at 1000
Initial SL price: 950
TP price:1100

a. if the price drops to 950 or lower, my SL will be triggered
b. if the price does not move, neither the SL nor the TP will trigger
c. 1. if the price rallies up to 1020 i.e a 2% increase, my SL will revise to 970 (1x TSL)
2. if the price rallies up to 1072 i.e a 7.5% increase, my SL will revise to 1010 (3x TSL)
3. if the price rallies up to 1081 i.e an 8.1% increase, my SL will revise to 1030 (4x TSL)

If you want to calculate and check TSL, You can download a copy of the TSL Calculator here.

How TSL works in Backtest?

Now, let us understand how TSL is tracked in a backtest.

Once a backtest is run, Streak fetches the historical data of instruments listed in the strategy and calculates the indicators required for the test, and analyzes the correct entry point.

After the Entry conditions become true, a trade entry is assumed at the Open price of the next candle (Trade candle). After the trade is entered, the system runs the following checks

a. Check if the Low of the current candle (Trade candle) is Lower than the initial SL level: if this is True, SL is triggered. If Low is higher than the initial SL, point b is checked

b. Check if High is higher than the TP level: if this is True, TP is triggered. If High is lower than TP, point c is checked

c. Check if the minimum TSL movement has happened. Since TSL is both the qualifier and the increment, the SL is trailed by the number of times TSL was qualified

Example: If TSL is 3 points for a long position, a minimum of 3 point movement in the upside is required for the TSL to come into action and trail.

d. Check if the Close of the current candle is lower than the TSL level from point c: if the Close is lower than the TSL, TSL is triggered. If Close is higher than the TSL, the next candle is checked…

TSL flow in Backtest (Trade Candle)

We will now move on to the second candle. We already have a TSL level from the previous candle and now the following checks would be performed by the system.

a. Check if the current Candle (next candle) Open is lower than the TSL: if this is True, TSL is triggered. If Open is higher than the TSL, point b is checked

b. Check if the current Candle(next) Open is Higher than the TP: if this is True, TP is triggered. If Open is lower than the TP level, point c is checked

Note: point a and b are to take care of Gap up and Gap down situations

c. Check if the Low of the current candle is Lower than the TSL level: if this is True, TSL is triggered. If Low is higher than the TSL, point d is checked

d. Check if High is higher than the TP level: if this is True, TP is triggered. If High is lower than TP, point e is checked

e. Check if the minimum TSL movement has happened: If this is True, the SL is trailed by the number of times TSL was qualified

f. Check if the Close of the current candle is lower than the TSL level from point e: if the Close is lower than the TSL, TSL is triggered. If Close is higher than the TSL, the next candle is checked..

TSL flow in Backtest (Next Candle)

Hope this helps you understand how Streak’s backtest logic works and how the System trails your TSL and takes care of each situation.

Assumption

Every Backtesting system in the world has some assumption on the basis of which a backtest is performed and here in Streak, the following assumptions are considered while backtesting using TSL

  1. Entry takes place at the Open price of the next candle
  2. For a Long position, the candle Sequence if O>>L>>H>>C i.e the Low is assumed to come first, followed by the High and then of course the Close (OLHC)
  3. For a Short position, the candle Sequence if O>>H>>L>>C i.e the High is assumed to come first, followed by the Low and then the Close (OHLC)
Candle Formation logic for TSL

Assumptions 2 and 3 are considered to avoid showing an optimistic backtest result. If an OHLC sequence is assumed for a Long position, instead of OLHC, then the TSL will always be trailed whereas in the live market the Low may come first and take out your SL. Since SL< TSL, you would see a better, more lucrative backtest result. Vice versa for a Short position.

A lot of research and testing has been done to arrive at the model that is currently implemented. However, there still may be some differences in a backtest result and a live trade primarily because of Slippage and if the price moves in a W pattern and hits the TSL.

In case you have any doubts, please write to support@streak.tech.