Number formats for indicator() and str.tostring: format.price, format.mintick, format.percent, format.volume and format.inherit.
format.* constants go in the format argument of indicator() and strategy(), and in the format argument of str.tostring. format.price shows numbers with the symbol's price precision. format.mintick rounds to the symbol's minimum tick. format.percent adds a percent sign. format.volume shortens large numbers with K, M and B suffixes. format.inherit, the default, takes the format from the chart.
The format is a display setting: it changes how a value is shown on the price scale, status line and in text, not the value the script computes.
Constants
| Name | Value | Description |
|---|---|---|
format.inherit | inherit | Use the chart's own format; the default. |
format.mintick | mintick | Round to the symbol's minimum tick. |
format.percent | percent | Show a percent sign after the number. |
format.price | price | Use the symbol's price precision. |
format.volume | volume | Shorten large numbers with K, M and B suffixes. |
Remarks
- The precision argument of indicator() sets the number of decimals when the format needs them.
Example
//@version=6
indicator("Formats", format = format.percent, precision = 2)
change = (close / close[1] - 1) * 100
plot(change, "Change", change >= 0 ? color.green : color.red, style = plot.style_columns)
if barstate.islast
label.new(bar_index, change, "Vol " + str.tostring(volume, format.volume) + "\nClose " + str.tostring(close, format.mintick))See also
Runs on Sidechair