array
Arrays (also callable as methods: a.push(x)).
#Functions
#array.absfunction
A new array of absolute values.
array.abs(id: array<num>): array<num>| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
Returns array<num>.
Example
const a = array.from(1.0, 2.0, 3.0)
const b = a.abs()Since ChartScript 1
#array.avgfunction
The average of the elements.
array.avg(id: array<num>): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const v = a.avg()Since ChartScript 1
#array.binary_searchfunction
Binary search in a sorted array (exact).
array.binary_search(id: array<num>, val: float): int| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
val | float | The value to search for. |
Returns int.
Example
const a = array.from(1.0, 2.0, 3.0)
const i = a.binary_search(2.0)Since ChartScript 1
#array.binary_search_leftmostfunction
Binary search in a sorted array (exact leftmost).
array.binary_search_leftmost(id: array<num>, val: float): int| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
val | float | The value to search for. |
Returns int.
Example
const a = array.from(1.0, 2.0, 3.0)
const i = a.binary_search_leftmost(2.0)Since ChartScript 1
#array.binary_search_rightmostfunction
Binary search in a sorted array (exact rightmost).
array.binary_search_rightmost(id: array<num>, val: float): int| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
val | float | The value to search for. |
Returns int.
Example
const a = array.from(1.0, 2.0, 3.0)
const i = a.binary_search_rightmost(2.0)Since ChartScript 1
#array.clearfunction
Removes every element.
array.clear(id: array<T>)| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
Example
const a = array.from(1.0, 2.0, 3.0)
a.clear()Since ChartScript 1
#array.concatfunction
Appends id2 to id1 and returns id1.
array.concat(id1: array<T>, id2: array<T>): array<T>| Parameter | Type | Description |
|---|---|---|
id1 | array<T> | The first array. |
id2 | array<T> | The second array. |
Returns array<T>.
Example
const a = array.from(1.0, 2.0, 3.0)
const b = array.from(4.0)
a.concat(b)Since ChartScript 1
#array.copyfunction
A shallow copy.
array.copy(id: array<T>): array<T>| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
Returns array<T>.
Example
const a = array.from(1.0, 2.0, 3.0)
const b = a.copy()Since ChartScript 1
#array.covariancefunction
Covariance of two arrays.
array.covariance(id1: array<num>, id2: array<num>, { biased?: bool = true }): float| Parameter | Type | Description |
|---|---|---|
id1 | array<num> | The first array. |
id2 | array<num> | The second array. |
biased | booldefault true | true: divide by n; false: divide by n - 1. |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const b = array.from(3.0, 2.0, 1.0)
const c = a.covariance(b)Since ChartScript 1
#array.everyfunction
true when every element is true.
array.every(id: array<bool>): bool| Parameter | Type | Description |
|---|---|---|
id | array<bool> | The array. |
Returns bool.
Example
const f = array.from(true, false)
const b = f.every()Since ChartScript 1
#array.fillfunction
Sets elements from index_from to index_to to value.
array.fill(id: array<T>, value: T, { index_from?: int = 0, index_to?: int = na })| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
value | T | The value. |
index_from | intdefault 0 | The first index (inclusive). |
index_to | intdefault na | The last index (exclusive). |
Example
const a = array.from(1.0, 2.0, 3.0)
a.fill(0.0)Since ChartScript 1
#array.firstfunction
The first element.
array.first(id: array<T>): T| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
Returns T.
Example
const a = array.from(1.0, 2.0, 3.0)
const x = a.first()Since ChartScript 1
#array.fromfunction
A new array of the arguments.
array.from(arg0: T, …): array<T>| Parameter | Type | Description |
|---|---|---|
arg0 | T | The first element. |
Returns array<T>.
Example
const a = array.from(1, 2, 3)Since ChartScript 1
#array.getfunction
The element at index (an error past the end).
array.get(id: array<T>, index: int): T| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
index | int | The element index (negative counts from the end). |
Returns T.
Example
const a = array.from(1.0, 2.0, 3.0)
const x = a.get(0)Since ChartScript 1
#array.includesfunction
true when the value is an element.
array.includes(id: array<T>, value: T): bool| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
value | T | The value. |
Returns bool.
Example
const a = array.from(1.0, 2.0, 3.0)
const b = a.includes(2.0)Since ChartScript 1
#array.indexoffunction
The first index of the value, or -1.
array.indexof(id: array<T>, value: T): int| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
value | T | The value. |
Returns int.
Example
const a = array.from(1.0, 2.0, 3.0)
const i = a.indexof(2.0)Since ChartScript 1
#array.insertfunction
Inserts an element at index.
array.insert(id: array<T>, index: int, value: T)| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
index | int | The element index (negative counts from the end). |
value | T | The value. |
Example
const a = array.from(1.0, 2.0, 3.0)
a.insert(1, 1.5)Since ChartScript 1
#array.joinfunction
The elements as text.
array.join(id: array<T>, { separator?: string = "" }): string| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
separator | stringdefault "" | The text placed between the parts. |
Returns string.
Example
const a = array.from(1.0, 2.0, 3.0)
const s = a.join(", ")Since ChartScript 1
#array.lastfunction
The last element.
array.last(id: array<T>): T| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
Returns T.
Example
const a = array.from(1.0, 2.0, 3.0)
const x = a.last()Since ChartScript 1
#array.lastindexoffunction
The last index of the value, or -1.
array.lastindexof(id: array<T>, value: T): int| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
value | T | The value. |
Returns int.
Example
const a = array.from(1.0, 2.0, 3.0)
const i = a.lastindexof(2.0)Since ChartScript 1
#array.maxfunction
The largest element (nth = 1: the next one down).
array.max(id: array<num>, { nth?: int = 0 }): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
nth | intdefault 0 | Which value: 0 = the extreme, 1 = the next, ... |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const v = a.max()Since ChartScript 1
#array.medianfunction
The median.
array.median(id: array<num>): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const v = a.median()Since ChartScript 1
#array.minfunction
The smallest element (nth = 1: the next one up).
array.min(id: array<num>, { nth?: int = 0 }): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
nth | intdefault 0 | Which value: 0 = the extreme, 1 = the next, ... |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const v = a.min()Since ChartScript 1
#array.modefunction
The most frequent element.
array.mode(id: array<num>): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const v = a.mode()Since ChartScript 1
#array.new_boolfunction
A new array of bool.
array.new_bool({ size?: int = 0, initial_value?: bool = false }): array<bool>| Parameter | Type | Description |
|---|---|---|
size | intdefault 0 | The number of elements. |
initial_value | booldefault false | The value every element starts with. |
Returns array<bool>.
Example
const a = array.new_bool(3)Since ChartScript 1
#array.new_boxfunction
A new array of boxs (na by default).
array.new_box({ size?: int = 0, initial_value?: box = na }): array<box>| Parameter | Type | Description |
|---|---|---|
size | intdefault 0 | The number of elements. |
initial_value | boxdefault na | The value every element starts with. |
Returns array<box>.
Example
const a = array.new_box()Since ChartScript 1
#array.new_colorfunction
A new array of color.
array.new_color({ size?: int = 0, initial_value?: color = na }): array<color>| Parameter | Type | Description |
|---|---|---|
size | intdefault 0 | The number of elements. |
initial_value | colordefault na | The value every element starts with. |
Returns array<color>.
Example
const a = array.new_color(3)Since ChartScript 1
#array.new_floatfunction
A new array of float.
array.new_float({ size?: int = 0, initial_value?: float = na }): array<float>| Parameter | Type | Description |
|---|---|---|
size | intdefault 0 | The number of elements. |
initial_value | floatdefault na | The value every element starts with. |
Returns array<float>.
Example
const a = array.new_float(3)Since ChartScript 1
#array.new_intfunction
A new array of int.
array.new_int({ size?: int = 0, initial_value?: int = na }): array<int>| Parameter | Type | Description |
|---|---|---|
size | intdefault 0 | The number of elements. |
initial_value | intdefault na | The value every element starts with. |
Returns array<int>.
Example
const a = array.new_int(3)Since ChartScript 1
#array.new_labelfunction
A new array of labels (na by default).
array.new_label({ size?: int = 0, initial_value?: label = na }): array<label>| Parameter | Type | Description |
|---|---|---|
size | intdefault 0 | The number of elements. |
initial_value | labeldefault na | The value every element starts with. |
Returns array<label>.
Example
const a = array.new_label()Since ChartScript 1
#array.new_linefunction
A new array of lines (na by default).
array.new_line({ size?: int = 0, initial_value?: line = na }): array<line>| Parameter | Type | Description |
|---|---|---|
size | intdefault 0 | The number of elements. |
initial_value | linedefault na | The value every element starts with. |
Returns array<line>.
Example
const a = array.new_line()Since ChartScript 1
#array.new_linefillfunction
A new array of linefills (na by default).
array.new_linefill({ size?: int = 0, initial_value?: linefill = na }): array<linefill>| Parameter | Type | Description |
|---|---|---|
size | intdefault 0 | The number of elements. |
initial_value | linefilldefault na | The value every element starts with. |
Returns array<linefill>.
Example
const a = array.new_linefill()Since ChartScript 1
#array.new_stringfunction
A new array of string.
array.new_string({ size?: int = 0, initial_value?: string = na }): array<string>| Parameter | Type | Description |
|---|---|---|
size | intdefault 0 | The number of elements. |
initial_value | stringdefault na | The value every element starts with. |
Returns array<string>.
Example
const a = array.new_string(3)Since ChartScript 1
#array.new_tablefunction
A new array of tables (na by default).
array.new_table({ size?: int = 0, initial_value?: table = na }): array<table>| Parameter | Type | Description |
|---|---|---|
size | intdefault 0 | The number of elements. |
initial_value | tabledefault na | The value every element starts with. |
Returns array<table>.
Example
const a = array.new_table()Since ChartScript 1
#array.new<T>function
A new array of the element type in <>.
Returns array<T>.
Example
const a = array.new<float>(3, 0)Since ChartScript 1
#array.percentile_linear_interpolationfunction
Percentile by linear interpolation.
array.percentile_linear_interpolation(id: array<num>, percentage: float): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
percentage | float | A percentage from 0 to 100. |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const p = a.percentile_linear_interpolation(50)Since ChartScript 1
#array.percentile_nearest_rankfunction
Percentile by the nearest-rank method.
array.percentile_nearest_rank(id: array<num>, percentage: float): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
percentage | float | A percentage from 0 to 100. |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const p = a.percentile_nearest_rank(50)Since ChartScript 1
#array.percentrankfunction
Percent of elements at or below the element at index.
array.percentrank(id: array<num>, index: int): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
index | int | The element index (negative counts from the end). |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const p = a.percentrank(1)Since ChartScript 1
#array.popfunction
Removes and returns the last element.
array.pop(id: array<T>): T| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
Returns T.
Example
const a = array.from(1.0, 2.0, 3.0)
const x = a.pop()Since ChartScript 1
#array.pushfunction
Adds an element at the end.
array.push(id: array<T>, value: T)| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
value | T | The value. |
Example
const a = array.from(1.0, 2.0, 3.0)
a.push(4.0)Since ChartScript 1
#array.rangefunction
max - min.
array.range(id: array<num>): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const v = a.range()Since ChartScript 1
#array.removefunction
Removes and returns the element at index.
array.remove(id: array<T>, index: int): T| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
index | int | The element index (negative counts from the end). |
Returns T.
Example
const a = array.from(1.0, 2.0, 3.0)
const x = a.remove(1)Since ChartScript 1
#array.reversefunction
Reverses in place.
array.reverse(id: array<T>)| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
Example
const a = array.from(1.0, 2.0, 3.0)
a.reverse()Since ChartScript 1
#array.setfunction
Sets the element at index.
array.set(id: array<T>, index: int, value: T)| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
index | int | The element index (negative counts from the end). |
value | T | The value. |
Example
const a = array.from(1.0, 2.0, 3.0)
a.set(0, close)Since ChartScript 1
#array.shiftfunction
Removes and returns the first element.
array.shift(id: array<T>): T| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
Returns T.
Example
const a = array.from(1.0, 2.0, 3.0)
const x = a.shift()Since ChartScript 1
#array.sizefunction
The number of elements.
array.size(id: array<T>): int| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
Returns int.
Example
const a = array.from(1.0, 2.0, 3.0)
const n = a.size()Since ChartScript 1
#array.slicefunction
A new array of part of the elements.
array.slice(id: array<T>, index_from: int, index_to: int): array<T>| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
index_from | int | The first index (inclusive). |
index_to | int | The last index (exclusive). |
Returns array<T>.
Example
const a = array.from(1.0, 2.0, 3.0)
const b = a.slice(0, 2)Since ChartScript 1
#array.somefunction
true when any element is true.
array.some(id: array<bool>): bool| Parameter | Type | Description |
|---|---|---|
id | array<bool> | The array. |
Returns bool.
Example
const f = array.from(true, false)
const b = f.some()Since ChartScript 1
#array.sortfunction
Sorts in place (stable); for an array of objects, sort_field names the field to sort by.
array.sort(id: array<T>, { order?: order = order.ascending, sort_field?: const string = na })| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
order | orderdefault order.ascending | order.ascending or order.descending. |
sort_field | const stringdefault na | For an array of a user type: the field to sort by. |
Example
const a = array.from(1.0, 2.0, 3.0)
a.sort(order.descending)Since ChartScript 1
#array.sort_indicesfunction
The indices that would sort the array.
array.sort_indices(id: array<T>, { order?: order = order.ascending, sort_field?: const string = na }): array<int>| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
order | orderdefault order.ascending | order.ascending or order.descending. |
sort_field | const stringdefault na | For an array of a user type: the field to sort by. |
Returns array<int>.
Example
const a = array.from(1.0, 2.0, 3.0)
const ix = a.sort_indices()Since ChartScript 1
#array.standardizefunction
A new array of z-scores.
array.standardize(id: array<num>): array<float>| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
Returns array<float>.
Example
const a = array.from(1.0, 2.0, 3.0)
const z = a.standardize()Since ChartScript 1
#array.stdevfunction
The standard deviation of the elements.
array.stdev(id: array<num>, { biased?: bool = true }): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
biased | booldefault true | true: divide by n; false: divide by n - 1. |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const v = a.stdev()Since ChartScript 1
#array.sumfunction
The sum of the elements.
array.sum(id: array<num>): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const v = a.sum()Since ChartScript 1
#array.unshiftfunction
Adds an element at the start.
array.unshift(id: array<T>, value: T)| Parameter | Type | Description |
|---|---|---|
id | array<T> | The array. |
value | T | The value. |
Example
const a = array.from(1.0, 2.0, 3.0)
a.unshift(0.0)Since ChartScript 1
#array.variancefunction
The variance of the elements.
array.variance(id: array<num>, { biased?: bool = true }): float| Parameter | Type | Description |
|---|---|---|
id | array<num> | The array. |
biased | booldefault true | true: divide by n; false: divide by n - 1. |
Returns float.
Example
const a = array.from(1.0, 2.0, 3.0)
const v = a.variance()Since ChartScript 1