Skip to content
TradequixDocsOpen the terminal
OverviewStart here, search, progress
  • Introduction
  • Quickstart
  • How a script runs
  • Types and qualifiers
  • Operators, conditionals and loops
  • Functions and methods
  • Objects and enums
  • Arrays, matrices and maps
  • Strings and colours
  • Time and sessions
  • Bar states
  • Plotting
  • Inputs
  • Technical analysis
  • Drawings and tables
  • Multiple timeframes
  • Strategies
  • Alerts in scripts
  • Repainting
  • The Pine editor
  • Indicator settings
  • Coming from TradingView
  • The data
  • Publish and sell
  • Catalogue and community
  • Your dashboard and earnings
  • Errors and debugging
  • Limits
  • Coverage
  • Built-in catalogue
  • Cookbook
  • Write Pine with AI
  • FAQ
  • Glossary
  • Cheat sheet
  • Function reference
  • Will it run here?
  • Error index

Language

Arrays, matrices and maps

Collections of values: rolling windows with arrays, grids with matrices, and lookups with maps. Up to 100,000 elements each.

View as MarkdownOpen in ClaudeOpen in ChatGPT

Arrays#

An array holds a list of one type. Declare it with var so it survives between bars, otherwise you get a new empty array every bar.

RunnableRolling median of ranges
1//@version=62indicator("Rolling median of ranges")3var array<float> ranges = array.new<float>()4ranges.push(high - low)5if ranges.size() > 506 ranges.shift()7plot(ranges.median(), "Median range", color = color.orange)8plot(high - low, "Range", color = color.new(color.gray, 50), style = plot.style_columns)

The pattern above is a rolling window: push the newest, shift the oldest once it is long enough.

Common functions: push, pop, shift, unshift, get, set, size, sum, avg, median, max, min, stdev, sort, includes, indexof, slice, join. The full list is in the reference.

Matrices#

A two-dimensional grid: matrix.new<float>(rows, columns, initial), then get, set, row, col, transpose, mult and more.

Maps#

Key-value lookups: map.new<string, float>(), then put, get, contains, remove, keys, values.

pine
1var map<string, float> levels = map.new<string, float>()2levels.put("high", ta.highest(high, 20))3levels.put("low", ta.lowest(low, 20))4plot(levels.get("high"))

Limits#

Arrays, matrices and tables hold at most 100,000 elements; asking for more stops the script with "The requested size exceeds the 100000 element limit". Index out of range is a runtime error naming the line.

PreviousObjects and enumsNext Strings and colours

On this page

  • Arrays
  • Matrices
  • Maps
  • Limits

Use with AI

View as MarkdownOpen in ClaudeOpen in ChatGPT