> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Arrays across languages

> How Lipi maps to MQL4, MQL5, NinjaScript, Pine Script and thinkScript for arrays: create an array, arrays of drawing objects, read and write an element, number of elements, add or remove at the end, add or remove at the start and more, with the differences that matter when converting.

Creating and working with arrays. Each row maps one concept from Lipi to the other languages; the word in a cell is the relation, explained in the [language map overview](https://gocharting.com/docs/scripting/reference/language-map.md#relations).

| Concept | Lipi | MQL4 | MQL5 | NinjaScript | Pine Script | thinkScript |
| - | - | - | - | - | - | - |
| [Create an array](#array-create) | `array.new`, `array.from`, `array.new_float`, `array.new_int` | Caveat | Caveat | Caveat | Caveat | Absent |
| [Arrays of drawing objects](#array-object-arrays) | `array.new_line`, `array.new_label`, `array.new_box` | Absent | Caveat | Caveat | Exact | Absent |
| [Read and write an element](#array-get-set) | `array.get`, `array.set` | Caveat | Caveat | Caveat | Differs | Absent |
| [Number of elements](#array-size) | `array.length` | Exact | Exact | Caveat | Caveat | Absent |
| [Add or remove at the end](#array-push-pop) | `array.push`, `array.pop` | Absent | Caveat | Caveat | Caveat | Absent |
| [Add or remove at the start](#array-shift-unshift) | `array.unshift`, `array.shift` | Absent | Caveat | Caveat | Caveat | Absent |
| [Insert or remove at a position](#array-insert-remove) | `array.insert`, `array.remove` | Absent | Caveat | Caveat | Caveat | Absent |
| [Empty or fill an array](#array-clear-fill) | `array.clear`, `array.fill` | Caveat | Caveat | Caveat | Exact | Absent |
| [First and last element](#array-first-last) | `array.first`, `array.last` | Absent | Absent | Caveat | Exact | Absent |
| [Find an element](#array-search) | `array.includes`, `array.indexof`, `array.lastindexof`, `array.binary_search` | Differs | Differs | Caveat | Caveat | Absent |
| [Copy, slice and join arrays](#array-copy-slice) | `array.copy`, `array.slice`, `array.concat` | Caveat | Caveat | Caveat | Caveat | Absent |
| [Sort and reverse](#array-sort) | `array.sort`, `array.sort_indices`, `array.reverse` | Caveat | Caveat | Caveat | Caveat | Absent |
| [Statistics of an array](#array-stats) | `array.sum`, `array.avg`, `array.min`, `array.max`, `array.median`, `array.stdev`, `array.variance` | Differs | Differs | Caveat | Caveat | Absent |
| [Array to text](#array-join) | `array.join` | Absent | Absent | Caveat | Exact | Absent |
| [Test all or any elements](#array-every-some) | `array.every`, `array.some` | Absent | Absent | Caveat | Exact | Absent |

Each section below gives the Lipi construct first, then the construct in each language, with a note wherever behaviour differs. The language name links to the documentation the row was checked against.

## Create an array

Creates an array of the given length.

In Lipi: `array.new`, `array.from`, `array.new_float`, `array.new_int`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array/arrayinitialize#ArrayInitialize) | `type name[n] declaration, ArrayResize, ArrayInitialize` | Equivalent, with a caveat | Fixed size at declaration, or a dynamic array sized with ArrayResize; fill values with ArrayInitialize. No from-values constructor. State and side effects: elements added by ArrayResize hold undefined values until you set them. |
| [MQL5](https://www.mql5.com/en/docs/array/arrayinitialize) | `ArrayResize, ArrayInitialize` | Equivalent, with a caveat | Declare a dynamic array, size it with ArrayResize, then fill with ArrayInitialize. A brace list initialises a fixed array. New elements are undefined until set. State and side effects: Elements added by ArrayResize are not initialised to any value. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | `new List<double>()` | Equivalent, with a caveat | A List\<T> grows like a Lipi array. new List\<double>(n) only sets capacity: add n items to reach that length. C# arrays are fixed length. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.new<type>, array.from, array.new_float, array.new_int` | Equivalent, with a caveat | Lipi caps arrays at 10000 elements versus Pine's 100000; array.new\<bool>(n) holds na in Lipi. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No script-created array. IDataHolder is the built-in series type (close, volume); rolling windows come from functions and fold. |

## Arrays of drawing objects

Creates an array of `line` IDs with `size` elements, each set to `initial_value`.

In Lipi: `array.new_line`, `array.new_label`, `array.new_box`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/objects/objectcreate) | | Not in MQL4 | Objects are named, not handles: ObjectCreate takes an object\_name string, so keep an array of names. |
| [MQL5](https://www.mql5.com/en/docs/objects) | `string[] of object names with ObjectCreate` | Equivalent, with a caveat | Chart objects are addressed by a name string, unique per chart. Keep the names in a string array; there are no object id handles. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | List\<IDrawingTool> (a typed list of draw objects) | Equivalent, with a caveat | Draw.\* methods return draw objects you can add to a List\<T>; entries are added as created, not preallocated with an initial value. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.new_line, array.new_label, array.new_box` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No arrays and no line, label or box objects to hold in them. |

## Read and write an element

Returns the element at `index`.

In Lipi: `array.get`, `array.set`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/basis/variables) | `array[index]` | Equivalent, with a caveat | Index operator, zero-based; an out-of-range access stops the program. A series-flagged array reverses the index direction. History indexing: ArraySetAsSeries makes index 0 the newest element; plain arrays count from the first. |
| [MQL5](https://www.mql5.com/en/docs/basis/variables) | `array[index]` | Equivalent, with a caveat | Plain bracket indexing, 0-based; an out-of-range index stops the program. ArraySetAsSeries can flip direction so index 0 is the newest element. History indexing: With the as-series flag set, index 0 is the newest element; Lipi arrays always start at the first element. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | `list[index] (List<T> indexer)` | Equivalent, with a caveat | Index syntax instead of array.get and array.set; zero-based as in Lipi. Out-of-range access throws an exception. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.get, array.set` | Looks alike, behaves differently | Pine accepts negative indexes counting from the end (-1 is the last element). Lipi stops the script on any index outside 0 to length-1. History indexing: array.get(a, -1) is the last element in Pine and a runtime error in Lipi. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/fold) | | Not in thinkScript | No element read or write on a user array. Past bars of a series are read with \[n] indexing or getValue inside fold. |

## Number of elements

Returns the number of elements in the array.

In Lipi: `array.length`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array/arraysize#ArraySize) | `ArraySize` | Exact | |
| [MQL5](https://www.mql5.com/en/docs/array/arraysize) | `ArraySize` | Exact | |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | List\<T>.Count (C# arrays: Length) | Equivalent, with a caveat | A property, not a function call. A fixed-length C# array uses Length instead of Count. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_array.size) | `array.size` | Equivalent, with a caveat | Lipi has no array.size or a.size; use array.length(a) or a.length. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No array length function; there are no user arrays. |

## Add or remove at the end

Appends `value` to the end of the array, growing it by one element.

In Lipi: `array.push`, `array.pop`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array) | | Not in MQL4 | No append or pop; grow with ArrayResize(array, n+1) and assign the last slot, read it and shrink to pop. |
| [MQL5](https://www.mql5.com/en/docs/array/arrayresize) | `ArrayResize` | Equivalent, with a caveat | No push or pop: grow with ArrayResize and assign the last slot. To pop, read the last element, then shrink the array. State and side effects: A reserve\_size argument avoids repeated reallocation; static arrays and indicator buffers cannot be resized. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | `List<T>.Add() with RemoveAt(Count - 1)` | Equivalent, with a caveat | Add appends like push. List\<T> has no Pop: read the last element, then call RemoveAt(Count - 1). |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.push, array.pop` | Equivalent, with a caveat | Pushing past 10000 elements stops a Lipi script; Pine allows 100000. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No append or remove operations; a series cannot be grown or shrunk by script. |

## Add or remove at the start

Inserts `value` at the beginning of the array.

In Lipi: `array.unshift`, `array.shift`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array/arraycopy) | | Not in MQL4 | No front insert or removal; ArrayCopy moves ranges, but copying an array onto itself is documented as undefined. |
| [MQL5](https://www.mql5.com/en/docs/array/arrayremove) | `ArrayRemove, ArrayInsert` | Equivalent, with a caveat | Remove index 0 with a count of 1; it returns a bool, not the element. ArrayInsert takes elements from a source array, not one value. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | `List<T>.Insert(0, value) and RemoveAt(0)` | Equivalent, with a caveat | Insert(0, value) matches unshift. List\<T> has no Shift: read item 0, then RemoveAt(0). Both move every later element. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.unshift, array.shift` | Equivalent, with a caveat | Unshifting past 10000 elements stops a Lipi script; Pine allows 100000. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No insert or remove at the start of a collection. |

## Insert or remove at a position

Inserts `value` at `index`, moving the element that was there, and every element after it, up one index.

In Lipi: `array.insert`, `array.remove`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array) | | Not in MQL4 | No insert or remove at a position; rebuild with ArrayCopy into a second array and ArrayResize. |
| [MQL5](https://www.mql5.com/en/docs/array/arrayinsert) | `ArrayInsert, ArrayRemove` | Equivalent, with a caveat | Insert copies elements from a source array at a destination index; remove takes a start and a count. Both return bool. State and side effects: On a fixed-size receiving array, the array's own size does not change. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | `List<T>.Insert() and RemoveAt()` | Equivalent, with a caveat | Same effect as inserting and removing at an index; both are methods on the list. RemoveAt returns nothing, as array.remove does. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.insert, array.remove` | Equivalent, with a caveat | Pine's array.remove returns the removed value; Lipi's returns nothing. Pine accepts negative indexes for both; Lipi errors outside 0 to length-1. History indexing: A negative index counts from the end in Pine and stops the script in Lipi. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No positional insert or remove on any collection. |

## Empty or fill an array

Removes every element, leaving an empty array.

In Lipi: `array.clear`, `array.fill`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array/arrayfill) | `ArrayFree, ArrayInitialize, ArrayFill` | Equivalent, with a caveat | ArrayFree empties dynamic arrays only; ArrayFill takes a start and a count, not an end index; ArrayInitialize sets every element. History indexing: ArrayFill always runs left to right and ignores the series-direction flag. |
| [MQL5](https://www.mql5.com/en/docs/array/arrayfill) | `ArrayFree, ArrayFill, ArrayInitialize` | Equivalent, with a caveat | ArrayFree empties a dynamic array. ArrayFill takes a start and a count, not an end index, and ignores the as-series direction. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | `List<T>.Clear()` | Equivalent, with a caveat | Clear() empties the list. List\<T> has no fill method; assign each index in a loop. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.clear, array.fill` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/Data-Conversion) | | Not in thinkScript | No clear or fill; a number passed as IDataHolder is read as a series of that constant. |

## First and last element

Returns the first element of the array.

In Lipi: `array.first`, `array.last`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array) | | Not in MQL4 | No first or last helper; read array\[0] and array\[ArraySize(array)-1]. |
| [MQL5](https://www.mql5.com/en/docs/array) | | Not in MQL5 | No dedicated functions; use index 0 and ArraySize minus 1, which swap meaning when the array is as-series. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | `list[0] and list[list.Count - 1]` | Equivalent, with a caveat | No First or Last property on List\<T>: index the ends directly. LINQ First() and Last() also exist. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.first, array.last` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No first or last element accessor on user arrays; there are none. |

## Find an element

Returns true when `value` is one of the array's elements.

In Lipi: `array.includes`, `array.indexof`, `array.lastindexof`, `array.binary_search`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array/arraybsearch) | `ArrayBsearch` | Looks alike, behaves differently | Needs a sorted numeric array and, when the value is missing, returns the index of the nearest element, not -1 or false. |
| [MQL5](https://www.mql5.com/en/docs/array/arraybsearch) | `ArrayBsearch` | Looks alike, behaves differently | Needs a sorted array and returns the nearest element's index when the value is absent, not -1. No includes or indexof function exists. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | `List<T>.Contains(), IndexOf(), LastIndexOf(), BinarySearch()` | Equivalent, with a caveat | Same job with close names. BinarySearch needs a sorted list. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.includes, array.indexof, array.lastindexof, array.binary_search` | Equivalent, with a caveat | Same results, -1 when missing. Pine's binary\_search target is named val (Lipi value) and has an extra sort\_field overload for arrays of user types. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No element search on collections. Highest, Lowest and GetMaxValueOffset locate extremes in a bar window only. |

## Copy, slice and join arrays

Returns a new array with the same elements.

In Lipi: `array.copy`, `array.slice`, `array.concat`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array/arraycopy#ArrayCopy) | `ArrayCopy` | Equivalent, with a caveat | Copies into an existing destination (grown as needed) and returns the copied count; slice by src\_start and count, concat by dst\_start. History indexing: copying runs left to right; series arrays have their start position adjusted for that. State and side effects: writes into the destination array; does not return a new array. |
| [MQL5](https://www.mql5.com/en/docs/array/arraycopy) | `ArrayCopy` | Equivalent, with a caveat | Copies a range into an existing destination and returns the count copied. A slice is a partial copy; concat copies at a destination offset. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | `List<T>.GetRange() and AddRange()` | Equivalent, with a caveat | GetRange(index, count) copies a range given a start and a count; AddRange appends another collection. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.copy, array.slice, array.concat` | Equivalent, with a caveat | Both slices are live views of the original. Pine says insertions and removals in a slice change the original; Lipi says adding may detach storage. State and side effects: Growing a slice keeps writing through to the original in Pine; in Lipi it may separate from the original. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No copy, slice or concatenate operations on collections. |

## Sort and reverse

Sorts the array in place.

In Lipi: `array.sort`, `array.sort_indices`, `array.reverse`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array/arraysort#ArraySort) | `ArraySort` | Equivalent, with a caveat | Numeric arrays only, sorted in place, returning a bool. No sort\_indices or reverse function. History indexing: the series-direction flag is taken into account when sorting. |
| [MQL5](https://www.mql5.com/en/docs/array/arraysort) | `ArraySort, ArrayReverse` | Equivalent, with a caveat | Ascending only, in place, ignoring the as-series flag. Sort descending with ArraySort then ArrayReverse. No index-sorting function. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1) | `List<T>.Sort() and Reverse()` | Equivalent, with a caveat | Sort() and Reverse() work in place, as array.sort and array.reverse do. There is no equivalent of sort\_indices. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.sort, array.sort_indices, array.reverse` | Equivalent, with a caveat | Pine array.sort and sort\_indices have a sort\_field overload for arrays of objects; Lipi takes only id and order. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/Median) | | Not in thinkScript | No sort or reverse function; Median sorts internally over a window but exposes only the middle value. |

## Statistics of an array

Returns the sum of the array's elements.

In Lipi: `array.sum`, `array.avg`, `array.min`, `array.max`, `array.median`, `array.stdev`, `array.variance`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array/arraymaximum) | `ArrayMaximum, ArrayMinimum` | Looks alike, behaves differently | Return the index of the extreme element, not its value. Sum, average, median, deviation and variance have no array functions. |
| [MQL5](https://www.mql5.com/en/docs/array/arraymaximum) | `ArrayMaximum, ArrayMinimum, MathMean, MathMedian, MathStandardDeviation, MathVariance` | Looks alike, behaves differently | ArrayMaximum and ArrayMinimum return an index, not the value. Mean, median, deviation and variance are separate Math functions; there is no array sum. History indexing: The returned index honours the as-series flag of the array. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable) | `Enumerable.Sum(), Average(), Min(), Max() (System.Linq)` | Equivalent, with a caveat | LINQ covers sum, average, min and max. Median, standard deviation and variance are not in LINQ; compute them by hand. Needs using System.Linq. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | array.sum, array.avg, array.min, array.max, array.median, array.stdev, array.variance | Equivalent, with a caveat | For int arrays Pine's avg, median, stdev and variance return int; Lipi's return float. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No statistics on user arrays. Rolling statistics over bars come from Sum, Average, Highest, Lowest, Median and StDev. |

## Array to text

Joins the elements into one string, with `separator` between them.

In Lipi: `array.join`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array) | | Not in MQL4 | No array-to-text function; loop over the elements and append with StringConcatenate or +. |
| [MQL5](https://www.mql5.com/en/docs/function_indices) | | Not in MQL5 | No join function; build the text in a loop with StringConcatenate or StringAdd. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.string.join) | `string.Join(separator, list)` | Equivalent, with a caveat | A static string method: separator first, then the collection of elements to join. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_array.join) | `array.join` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/IDataHolder) | | Not in thinkScript | No array-to-text function; there are no user arrays. |

## Test all or any elements

Returns true when every element is true.

In Lipi: `array.every`, `array.some`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/array) | | Not in MQL4 | No all-or-any test over elements; loop and test each one. |
| [MQL5](https://www.mql5.com/en/docs/array) | | Not in MQL5 | No all-true or any-true function in the array list; loop over the elements. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable) | `Enumerable.All() and Any() (System.Linq)` | Equivalent, with a caveat | LINQ All and Any take a condition function, so pass x => x for a list of bools. Needs using System.Linq. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `array.every, array.some` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/fold) | | Not in thinkScript | No all/any test on collections. A fold loop with a while condition can scan a bar window. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.