How to get tick size in PineScript?

How to get tick size in PineScript?

Quite often for your PineScript indicator or strategy, you need tick size. Of course, you can add it explicitly in your code. But this won’t work for all instruments and you’ll have to change the code for all instruments with different tick values.

Fortunately, there is a universal way to get tick value in PineScript that will allow your scripts to work for all instruments in TradingView. For that, you can use: syminfo.mintick built-in variable.

Here is a small script you can use to see tick size for the current symbol in Tradingview:

study("Get Min Tick")

l = label.new(bar_index, 1, "Min Tick: " + tostring(syminfo.mintick))

Real example of how it can be used in PineScript you can view in standard Pivot Reversal Strategy:

strategy("Pivot Reversal Strategy", overlay=true)

leftBars  = input(4)
rightBars = input(2)

swh = pivothigh(leftBars, rightBars)
swl = pivotlow(leftBars,  rightBars)

hprice = 0.0
lprice = 0.0

hprice := not na(swh) ? swh : hprice[1]
lprice := not na(swl) ? swl : lprice[1]

le = false
se = false

le := not na(swh) ? true : (le[1] and high > hprice ? false : le[1])
se := not na(swl) ? true : (se[1] and low  < lprice ? false : se[1])

if (le)
	strategy.entry("PivRevLE", strategy.long, comment="PivRevLE", stop=hprice + syminfo.mintick)
if (se)
	strategy.entry("PivRevSE", strategy.short, comment="PivRevSE", stop=lprice - syminfo.mintick)

Here we adjust levels by 1 tick for stop orders.

Follow me on TradingView and YouTube.

This image has an empty alt attribute; its file name is wide.png

Pine Script Programming Courses
Pine Script Programming Courses
Learn to build your own TradingView Indicators and Strategies
Sidebar Signup Form
If you want to be the first in this business, subscribe to the latest news