Tradingview – Working With Ticks

In this weeks post, we are going to take a look at working with ticks in Tradingview. In particular, we will focus on the lossandprofitparameters of strategy.exit(). Since these parameters require us to work with ticks instead of monetary unit, some newer users may avoid using them. After all, what is a tick anyway?

Official Docs

Before we start, let’s take a look at the parameters in question. As always, it is good to have a look at the official documentation first. When reading through the snippet of parameters below, you will see there are 2 different ways to set a stop loss or take profit.

profit (float) An optional parameter. Profit target (specified in ticks). If it is specified, a limit order is placed to exit market position when the specified amount of profit (in ticks) is reached. The default value is ‘NaN’.
limit (float) An optional parameter. Profit target (requires a specific price). If it is specified, a limit order is placed to exit market position at the specified price (or better). Priority of the parameter ‘limit’ is higher than priority of the parameter ‘profit’ (‘limit’ is used instead of ‘profit’, if its value is not ‘NaN’). The default value is ‘NaN’.
loss (float) An optional parameter. Stop loss (specified in ticks). If it is specified, a stop order is placed to exit market position when the specified amount of loss (in ticks) is reached. The default value is ‘NaN’.
stop (float) An optional parameter. Stop loss (requires a specific price). If it is specified, a stop order is placed to exit market position at the specified price (or worse). Priority of the parameter ‘stop’ is higher than priority of the parameter ‘loss’ (‘stop’ is used instead of ‘loss’, if its value is not ‘NaN’). The default value is ‘NaN’.
The key difference between the parameters is that each of them expects a different input. lossand profitexpect you to provide the number of ticks away from the entry price that you would like to exit. On the other hand, stopandlimitare set using a price level. Of the two, it is generally easier to work with price levels as these are readily available to us through OHLCdata, indicators and simple calculations. Additionally, most users will be familiar with setting stops at price level when manually trading and filling out an order form through their broker. However, that does not mean tick based stop and limit orders should be cast out of our armoury.

The Advantage to Working With Ticks

Working in ticks does have one key advantage. Ticks allow us to really fix our risk and reward ratios. Let’s imagine we want to set a stop and take profit with a risk-reward ratio of exactly 2:1, using the stopparameter (i.e. price levels) we have a couple of options:

  • Calculate it from the close value at the time we send our entry order. This is not perfect though because we do not enter at the close. We actually enter at the open of the following bar. If that following bar gaps up or down, then our stop and profit levels will be skewed.
  • We can wait until our entry order is filled before calculating it. However, this again is not ideal because the order would not be in the market until one bar later, leaving us unprotected for one bar.

By using ticks with the profitparametersloss, our stop and profit orders are immediately in the market and are measured from the entry price.

Minimum Ticks

Before we can use either parameter, we should take some time to understand what a tick is and the concept of a “minimum tick”. For those unfamiliar with the terms, a tick is the minimum value that the price can change/move up or down. So for example, if Barclays on the London Stock Exchange is quoted at 203.10 and has a minimum tick value of 0.05 pence, then the next closest prices which we could trade would be 203.15 or 203.05. Of course, we could blow past these values but we could never end up at 203.7 as it is not a multiple of 0.05.

As you might deduce, knowing the minimum tick level is useful for knowing where price could go next and for converting ticks back to a £ amount. 20 ticks with a min tick value of 0.5 pence is different to 20 ticks with a min tick of 0.2 (10 pence vs 4 pence).

So if the minimum tick value can vary so much, how can know what the tick value is? Fortunately, Tradingview has a built-in variable syminfo.mintickthat provides the minimum tick value of the instrument/asset you are trading.

Does a Minimum Tick Impact Stop and Limit Parameters?

Now we have a bit of background knowledge, it seems like a good time to take a little detour. If we know that an asset moves in fixed increments then do we need to be careful when setting stopandlimitprice levels?

Continuing from the example above, Barclays was quoted at 203.10 pence. Now let’s imagine we are going long and want a 10% stop loss. Normally we would just calculate 203.1 * 0.9 = 182.79and send a stop loss order at that level. Now you might rightly point out that 182.79 is not a multiple of 0.05 so let’s look at what happens if we do that…

Min Tick Test – Order Level

The following example must be run on BARC in order to replicate the results we see lower down. The code simply sends a stop order at the open on 3rd May 2018 (assuming you are using the daily timeframe) and sends it at a level that is not a multiple of the min tick.

Running the code we can see the actual fill level:

BARC Showing Fill level of a stop loss order

As you can see, we were filled at 205.45. This makes sense as it is the first available price below the requested stop level. So in conclusion, you do not need to accurately calculate your stop/limit orders to the nearest tick level. However, you should be aware, that the price you get filled at could be a little further out than expected.

Ticks With Loss And Profit

Ok, now time to revert back to the loss and profit parameters. Let’s take a look at a simple use case for setting loss in ticks and what that means in terms of price difference. Again, this should be run on BARC to replicate the result below.

You may nite that the code above has been edited slightly. An extra ticks input has been added and we also have a stratey.entry()call to enter a position. We must enter a position first in order to use the strategy.exit()function.

Working with ticks - Settings the Loss parameter

Using the default setting of 20 ticks we can see that it resulted in a 1 pence stop loss level. This is expected given that we know the minimum tick level is 0.05 pence.

What happens if you give a negative tick value?

It may seem logical to use a negative tick value for Long position stop losses and a positive tick value for Short positions. After all, for a long position, we want our stop to be below the entry price right? Well, Tradingview’s engine will do this conversion for you. As a result, you must use a positive tick value. Let’s take a look at what happens with a negative value:

We can use the same code as above but change the “Stoploss in Ticks” input value to -20 instead of 20. As we can see when we run the script, the order is filled immediately.

Showing what happens when a negative number is used to set loss or profit parameters


FX Has No Minimum Tick

Some inquisitive readers who use plot(syminfo.mintick)to see what the actual tick level is may notice that FX pairs tend to have a tick value of 0.

Picture showing FX pairs have a minimum tick of zero

So what does that mean for us? Nothing really…. This is because FX pairs are quoted in pips/pipettes. As such, we do not need to specify a minimum tick. A pipette IS the minimum tick value. We can’t divide it any further and we do not move in multiples of pipettes. Therefore if you input a 20 tick stop loss on a non-japanese pair, your stop will be 2 pips. This can be seen with the following code:

List of Trades

Picture showing that pipettes are ticks

As we can see from the list of trades, a 20 tick stop loss resulted in a 2 pip price difference. The 40 tick profit level resulted in a 4 pip difference. So we can see that price is able to tick without a minimum level and as such, a minimum tick level of zero is appropriate.

Find This Post Useful?

If this post saved you time and effort, please consider support the site! There are many ways to support us and some won’t even cost you a penny.