The type for whole numbers: bar counts, lengths, timestamps in milliseconds and indexes. An int can be na.
An int holds a whole number. bar_index, time, the length arguments of ta.* functions and the sizes of arrays are ints. A literal without a decimal point, such as 14 or -3, is an int.
Adding, subtracting or multiplying ints gives an int. Dividing two ints gives a float, so 7 / 2 is 3.5, not 3. To drop the fraction, wrap the result in int(), which truncates toward zero, or use math.floor(), math.round() or math.ceil() for the other roundings.
Remarks
- int(x) casts a float to an int by removing its fraction, and returns na for na. An int is assigned to a float freely; a float is assigned to an int only through a cast.
- The remainder operator works on ints: bar_index % 5 == 0 is true on every fifth bar.
- On Sidechair: int(x) truncates toward zero and returns na for na input.
Example
//@version=6
indicator("Every fifth bar", overlay = true)
fifth = bar_index % 5 == 0
half = int((high - low) / syminfo.mintick / 2)
plotshape(fifth, "Fifth", shape.circle, location.abovebar, color.blue, size = size.tiny)
plot(half, "Half range in ticks", color.gray)See also
Runs on Sidechair