Builds an array of whole numbers for counters, bar indexes and timestamps, empty by default or pre-filled to a size.
array.new_int(4, 0) is four whole-number slots set to 0, which suits counters, bar indexes and timestamps. With no arguments the array starts empty.
Without an initial_value the slots are na, and na plus 1 is still na. A counter built with array.new_int(5) never counts, so pass 0 as the second argument.
Syntax
array.new_int(size: series int (optional), initial_value: series int (optional)) -> array<int>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| size | series int | 0 | How many integer slots to start with: 0 or more, up to 100,000. Use a size such as 5 for a fixed set of counter buckets. |
| initial_value | series int | na | The whole number written into every starting slot. Pass 0 for counters, because an omitted value leaves na and na plus 1 stays na. |
Returns
array<int>: A new array of whole numbers with the requested size, every slot holding initial_value or na.
Remarks
- Putting a float into an int array is a type error in v6; wrap the value in int() or
math.round()first.
Example
//@version=6
indicator("array.new_int: RSI band counts", overlay = false)
var bands = array.new_int(5, 0)
r = ta.rsi(close, 14)
if not na(r)
band = math.min(4, int(r / 20))
array.set(bands, band, array.get(bands, band) + 1)
plot(array.get(bands, 0), "RSI 0-20", color.red)
plot(array.get(bands, 2), "RSI 40-60", color.gray)
plot(array.get(bands, 4), "RSI 80-100", color.green)See also
Runs on Sidechair