Skip to content
ChartDeck ChartScript docs Account Open the terminal

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>
ParameterTypeDescription
idarray<num>The array.

Returns array<num>.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.

Returns float.

Example

ChartScriptFragmentOpen in editor
const a = array.from(1.0, 2.0, 3.0)
const v = a.avg()

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
ParameterTypeDescription
idarray<num>The array.
valfloatThe value to search for.

Returns int.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.
valfloatThe value to search for.

Returns int.

Example

ChartScriptFragmentOpen in editor
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>)
ParameterTypeDescription
idarray<T>The array.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
id1array<T>The first array.
id2array<T>The second array.

Returns array<T>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
idarray<T>The array.

Returns array<T>.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
id1array<num>The first array.
id2array<num>The second array.
biasedbooldefault truetrue: divide by n; false: divide by n - 1.

Returns float.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<bool>The array.

Returns bool.

Example

ChartScriptFragmentOpen in editor
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 })
ParameterTypeDescription
idarray<T>The array.
valueTThe value.
index_fromintdefault 0The first index (inclusive).
index_tointdefault naThe last index (exclusive).

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.

Returns T.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
arg0TThe first element.

Returns array<T>.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.
indexintThe element index (negative counts from the end).

Returns T.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.
valueTThe value.

Returns bool.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.
valueTThe value.

Returns int.

Example

ChartScriptFragmentOpen in editor
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)
ParameterTypeDescription
idarray<T>The array.
indexintThe element index (negative counts from the end).
valueTThe value.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.
separatorstringdefault ""The text placed between the parts.

Returns string.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.

Returns T.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.
valueTThe value.

Returns int.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.
nthintdefault 0Which value: 0 = the extreme, 1 = the next, ...

Returns float.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.

Returns float.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.
nthintdefault 0Which value: 0 = the extreme, 1 = the next, ...

Returns float.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.

Returns float.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
sizeintdefault 0The number of elements.
initial_valuebooldefault falseThe value every element starts with.

Returns array<bool>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
sizeintdefault 0The number of elements.
initial_valueboxdefault naThe value every element starts with.

Returns array<box>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
sizeintdefault 0The number of elements.
initial_valuecolordefault naThe value every element starts with.

Returns array<color>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
sizeintdefault 0The number of elements.
initial_valuefloatdefault naThe value every element starts with.

Returns array<float>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
sizeintdefault 0The number of elements.
initial_valueintdefault naThe value every element starts with.

Returns array<int>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
sizeintdefault 0The number of elements.
initial_valuelabeldefault naThe value every element starts with.

Returns array<label>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
sizeintdefault 0The number of elements.
initial_valuelinedefault naThe value every element starts with.

Returns array<line>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
sizeintdefault 0The number of elements.
initial_valuelinefilldefault naThe value every element starts with.

Returns array<linefill>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
sizeintdefault 0The number of elements.
initial_valuestringdefault naThe value every element starts with.

Returns array<string>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
sizeintdefault 0The number of elements.
initial_valuetabledefault naThe value every element starts with.

Returns array<table>.

Example

ChartScriptFragmentOpen in editor
const a = array.new_table()

Since ChartScript 1

#array.new<T>function

A new array of the element type in <>.

Returns array<T>.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.
percentagefloatA percentage from 0 to 100.

Returns float.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.
percentagefloatA percentage from 0 to 100.

Returns float.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.
indexintThe element index (negative counts from the end).

Returns float.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.

Returns T.

Example

ChartScriptFragmentOpen in editor
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)
ParameterTypeDescription
idarray<T>The array.
valueTThe value.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.

Returns float.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.
indexintThe element index (negative counts from the end).

Returns T.

Example

ChartScriptFragmentOpen in editor
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>)
ParameterTypeDescription
idarray<T>The array.

Example

ChartScriptFragmentOpen in editor
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)
ParameterTypeDescription
idarray<T>The array.
indexintThe element index (negative counts from the end).
valueTThe value.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.

Returns T.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<T>The array.

Returns int.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
idarray<T>The array.
index_fromintThe first index (inclusive).
index_tointThe last index (exclusive).

Returns array<T>.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<bool>The array.

Returns bool.

Example

ChartScriptFragmentOpen in editor
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 })
ParameterTypeDescription
idarray<T>The array.
orderorderdefault order.ascendingorder.ascending or order.descending.
sort_fieldconst stringdefault naFor an array of a user type: the field to sort by.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
idarray<T>The array.
orderorderdefault order.ascendingorder.ascending or order.descending.
sort_fieldconst stringdefault naFor an array of a user type: the field to sort by.

Returns array<int>.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
idarray<num>The array.

Returns array<float>.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.
biasedbooldefault truetrue: divide by n; false: divide by n - 1.

Returns float.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.

Returns float.

Example

ChartScriptFragmentOpen in editor
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)
ParameterTypeDescription
idarray<T>The array.
valueTThe value.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
idarray<num>The array.
biasedbooldefault truetrue: divide by n; false: divide by n - 1.

Returns float.

Example

ChartScriptFragmentOpen in editor
const a = array.from(1.0, 2.0, 3.0)
const v = a.variance()

Since ChartScript 1

The ChartScript documentation is in English for now; translations will follow.