Black Friday 30% off Basic and ProBlack Friday −30%Ends in––d––h––m––sSee the deal

Text and numbers

Writing numbers in drawing texts, and reading what happens during the calculation.

f-string

F-strings are written in the simple form, f"RSI {value}": each brace writes the value like str(). Format specs inside the braces, like {x:.2f}, aren’t used: for numbers there is format.

format

The format functions write numbers the way the chart does: decimal point, no thousands separator, and nan as empty text.

FunctionExample
format.price(x)With the symbol’s decimals: 21534 → "21534.00"
format.quantity(x)Like volumes: 12345 → "12.3K"
format.percent(x)12.5 → "12.50%"
format.number(x, precision)format.number(1.23456, 2) → "1.23"
Python
high = bars.high[i]
draw.text((i, high), text={"value": f"High {format.price(high)}"})
A single number type

Integers and decimals are the same number: str(3.0) gives "3", and very large numbers are written in full. For text meant to be read, use format.

print

print writes to the Log tab of the console, with the calculation time and the code line; on the chart it does nothing. It helps you understand what the script calculates: you see the lines of the last calculation, up to 1000, and if the calculation stops with an error the lines written up to that point remain, with the error below.

Python
rsi = ta.rsi(bars.close, 14)
print("last RSI", rsi[-1])