Limits and budgets
What the platform bounds for every script. Steps per bar and per run, time, size, collections, drawings, alerts, requests, plus what is not available yet.
A script runs over a whole chart of bars, in your browser, when it is on a chart. So the platform sets limits, and a script cannot raise them. Every limit that stops a script gives an error that names the bar, the line and what was spent. This page lists them in one place. The numbers come from the engine itself.
Work done: steps and time#
| Limit | Value |
|---|---|
| Steps one bar may spend | 500,000 |
| Steps one whole run may spend | 600,000,000 |
| Clock time of one run on a chart | 5,000 ms |
| Functions of yours in progress at once, one inside another | 64 |
A step is a unit of work: a loop pass, a window or matrix walk, a drawing, one for every eight characters of text built. The count is of steps, not seconds, so a script stops at the same place on every machine. A bar that spends more than its share stops the script with E-LIMIT-OPS: The script takes too long on bar 0 …: this bar used more than … steps … (line 3). Time is checked as well; running out of it is E-LIMIT-TIME.
A loop that does not end is the usual way to meet the limit. The script stops on the first bar, and the message tells you where:
indicator "A loop that never ends"
edition = 1
mut n = 0
while true
n += 1
plot(n)A chain of your own functions that call one another can be 64 deep on a bar; one more stops the script with E-LIMIT-DEPTH. A function that calls itself, directly or through others, is refused before the script runs (E3310): write a loop instead.
A loop of a thousand passes on every bar is fine, since it costs a thousand of the 500,000 steps a bar has. If a script is slow, look first for a loop that does the same work on every bar.
History and size#
| Limit | Value |
|---|---|
| Bars of history a chart loads for a script, at least | 2,048 |
| Bars back that any one read or window may reach | 8,192 |
| Characters in a script | 400,000 |
| Tokens (words, numbers and signs) in a script | 250,000 |
| Characters in one line | 20,000 |
| Brackets nested, blocks nested, an expression nested | 64, 40, 100 |
| Errors the checker lists before it stops | 50 |
x[n] is na on the first n bars, and also when the chart simply has no bar that far back. That is the only meaning of na here: the value is not in the data. A read that goes back further than the platform allows, 8,192 bars, is never a na; it is an error. A number written in the script (x[9000], tech.sma(close, 9000)) is found before the script runs, E-LIMIT-HISTORY-STATIC. A number worked out while it runs (an input, a counter) stops the run on the bar, E-LIMIT-HISTORY; so does an input given a value above its own max, before the first bar (E-INPUT-RANGE).
A series keeps only the bars the text says it reads, so the memory of a script does not grow with the length of the chart when what it reads back is fixed. When nothing in the text bounds a read (an input without a max), the script runs and the series keeps up to the 8,192 bars; the editor says so with W-ENGINE-HISTORY-OPEN. Give such an input a max.
The number of scripts you can keep depends on your plan: the free chart plan keeps 2, MillionChart Pro up to 100. The editor says when you reach it.
Collections and text#
| Limit | Value |
|---|---|
| Items in an array, a map or a matrix | 100,000 |
| Characters in a text one call builds | 1,000,000 |
| Characters in a text of a drawing or a cell | 2,000 (cut, with a warning) |
A pattern of text.match: characters, instructions once repeats are written out, a repeat count | 256, 2,048, 1,000 |
Too many items is E-LIMIT-ITEMS, and too much text is E-LIMIT-TEXT. A pattern past its limits is E-LIMIT-REGEX.
Working memory#
| Limit | Value |
|---|---|
| Bytes the script holds at one moment (arrays, maps, texts, objects, drawings, history) | 134,217,728 |
| Bytes the script may build over a whole run, even what it let go | 2,147,483,648 |
The bytes are counted by the engine, in the same way on every machine; they are not the memory of the browser. Holding too much is E-LIMIT-MEMORY ("holds"), building too much over the run is the same code ("builds"). A request for another timeframe is counted in the same account as the script that makes it, not in an account of its own. A script that makes a temporary array on every bar and lets it go is not stopped by the first limit; only a script that keeps growing is.
Drawings and tables#
| Limit | Value |
|---|---|
| Lines, labels and boxes kept when the header says nothing | 50 |
Most you may ask for with max_lines, max_labels, max_boxes | 500 |
Most for max_polylines | 100 |
| A table: columns, rows, cells | 100, 500, 10,000 |
| Cells of all live tables together | 20,000 |
| Tables kept | 40 |
When a script makes more drawings than it keeps, the oldest are dropped and the run says how many (W-OBJECT-LIMIT). A table past its size is E-LIMIT-TABLE; a drawing past its size is E-LIMIT-DRAW.
Alerts#
Alerts on your own scripts are switched off in this release (see Alert keys and options); these are the limits the language sets for them.
| Limit | Value |
|---|---|
| Times a script may ring on one bar | 20 |
| Times it may ring in one run | 5,000 |
| Characters in an alert message | 4,096 (cut, with a warning) |
Requests and modules#
| Limit | Value |
|---|---|
| Different symbol-and-timeframe pairs a chart script may read | 20 |
| Modules importing modules, deep | 8 |
| Imports compiled for one script | 64 |
| Characters of module text compiled for one script | 1,000,000 |
Periods prior() may go back | 64 |
Numbers#
The mathematical functions give the same result on every supported device: one fixed implementation is used everywhere, the largest error measured on the current test set is at most 0.85 ulp, and correct rounding is not promised. Numbers explains this. A script that needs the part of the engine that holds them does not start without it (E-ENGINE-PART-UNAVAILABLE, E-ENGINE-PART-VERSION).
Not available yet#
These are planned or not offered. Writing one gives an error, so a script never runs with a meaning it was not written for; for some the message says that the form is reserved, for others it only says that the name or the option is not known.
- The
preset,bindandsecretinputs. - The blocks
on closeandon tick, thereportstatement and thebracketorder statement; these belong to a later edition. fundingandhedgein a strategy header.- Data of a symbol other than the chart's (
E4001), and the requests for a whole panel of symbols or for a scan of a list of them. - The names
account.*andcontract.*. - Items of a list written
items[i](useitems.at(i)) and the selectors on lists such as.where(...)and.count(...). - The helpers
pips(x)andto_ticks(d); multiply bysymbol.pipor divide bysymbol.tick. - A cooldown or an expiry written as
3 bars; write the number. alert.send(json(...)); build the text yourself.- Anonymous functions.
- Libraries supplied by the platform.
See also: Reading the editor's messages, Choices and loops.