Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

pine script - Get Decimals places in Pinescript

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?

question from:https://stackoverflow.com/questions/65642950/get-decimals-places-in-pinescript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...