Builds an array from the values you list, taking the item type from them.
array.from(1, 2, 3) is an array<int>, array.from(1.5, 2) an array<float>, and array.from("a", "b") an array<string>. The arguments are copied into the new array in the order written.
Use it to seed a var array with known levels, or to build a short list inline, such as the periods to loop over.
Syntax
array.from(arg0, arg1, ...: <arg..._type>) -> array<>
array.from(arg0, arg1, ...: series int) -> array<int>
array.from(arg0, arg1, ...: series int/float) -> array<float>
array.from(arg0, arg1, ...: series bool) -> array<bool>
array.from(arg0, arg1, ...: series string) -> array<string>
array.from(arg0, arg1, ...: series label) -> array<label>
array.from(arg0, arg1, ...: series line) -> array<line>
array.from(arg0, arg1, ...: series color) -> array<color>
array.from(arg0, arg1, ...: series enum) -> array<>
array.from(arg0, arg1, ...: series box) -> array<box>
array.from(arg0, arg1, ...: series table) -> array<table>
array.from(arg0, arg1, ...: series linefill) -> array<linefill>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| arg0, arg1, ... | <arg... | required | The items, separated by commas. The first non-na item decides the type of the array. |
Returns
array<> or array<int> or array<float> or array<bool> or array<string> or array<label> or array<line> or array<color> or array<box> or array<table> or array<linefill>: A new array holding the arguments.
Remarks
- All arguments need the same type; a mix of int and float becomes float.
- On Sidechair:
array.fromaccepts up to 10 values per call. Build longer lists witharray.push()in a loop.
Example
//@version=6
indicator("array.from: lengths", overlay = true)
lengths = array.from(10, 20, 50)
for i = 0 to array.size(lengths) - 1
len = array.get(lengths, i)
plot(ta.sma(close, len), "SMA " + str.tostring(len), i == 0 ? color.blue : i == 1 ? color.orange : color.red)See also
Runs on Sidechair