0
votes

A forex stock may have five decimals point like EURUSD 1.22189 Another may have two decimal points like BITCOIN/USD like 40102.16

I want the number of digits after the decimal point, i.e. 5 digits in EURUSD and 2 digits in BITCOIN/USD example above.

How do I achieve this in Pinescript?

1

1 Answers

0
votes

This will give you what you're looking for.

//@version=4
study("Decimals", overlay=true)

var int decimals = int(log10(1/syminfo.mintick))

if barstate.islast
    label.new(bar_index, high, tostring(decimals))

Improved version.

//@version=4
study("Decimals", overlay=true)

var int decimals = str.length(tostring(syminfo.mintick))-2

if barstate.islast
    label.new(bar_index, high, tostring(decimals))

Another implementation by KryptoNight can be found here.