Decimals
Decimals returns the number of decimal places of the current instrument in ProBuilder. Use Decimals to format output or size price offsets to the instrument's precision.
Syntax
DecimalsDecimals takes no index and returns a single integer for the instrument the code runs on.
How it works
Decimals reports how many digits appear after the decimal point in the instrument's price quotes. A stock quoted to two places returns 2, an index quoted in whole points returns 0, and a currency pair quoted to five places returns 5.
The value is a property of the instrument, not of any bar, so it does not change from one bar to the next and takes no bracket offset. It reflects the price precision the platform uses for that market.
Reading Decimals lets one script behave sensibly across instruments of different precision. It is useful for building a smallest-step offset, deciding how to round a computed level, or formatting a value for display so the number of shown digits matches the market.
Examples
Example 1, Reporting the instrument precision (Indicator)
// Show how many decimals the current instrument uses
numDecimals = Decimals
RETURN numDecimals AS "Decimals"The indicator plots a flat line at the instrument's decimal count, confirming its quoting precision.
Example 2, Screening by quoting precision (ProScreener)
// Instruments quoted to more than two decimal places
precise = Decimals > 2
SCREENER[precise] (Decimals AS "Decimals")The screener isolates instruments whose prices carry more than two decimal places.
Example 3, Precision-aware offset (ProOrder)
DEFPARAM CumulateOrders = false
// One smallest price unit, derived from the instrument's decimals
oneUnit = Pow(10, -Decimals)
IF Close CROSSES OVER Average[20](Close) THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Place the stop one unit below the recent low
IF LONGONMARKET THEN
SELL AT Lowest[10](Low) - oneUnit STOP
ENDIFThe stop offset is built from Decimals, so it scales to each instrument's smallest quoted step.
Common errors and gotchas
- Not a tick size.
Decimalsgives the count of decimal places, not the minimum price increment. Instruments that tick in steps larger than one decimal unit needPOINTSIZEorTICKSIZEfor the true step. - Fixed per instrument. The value does not vary across bars, so applying a bracket offset like
Decimals[1]is meaningless. - Zero for whole-number quotes. Instruments priced in whole units return 0, so code that divides by
Decimalsmust guard against that case.
Related instructions
Close, the closing price of a bar.Open, the opening price of a bar.High, the highest price of a bar.Low, the lowest price of a bar.Range, the high minus low of a bar.TypicalPrice, the average of high, low, and close.Volume, the traded volume of a bar.CustomClose, the user-selectable price source.
