millionchart
فارسی

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#

LimitValue
Steps one bar may spend500,000
Steps one whole run may spend600,000,000
Clock time of one run on a chart5,000 ms
Functions of yours in progress at once, one inside another64

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:

Cuprel · error E-LIMIT-OPS
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#

LimitValue
Bars of history a chart loads for a script, at least2,048
Bars back that any one read or window may reach8,192
Characters in a script400,000
Tokens (words, numbers and signs) in a script250,000
Characters in one line20,000
Brackets nested, blocks nested, an expression nested64, 40, 100
Errors the checker lists before it stops50

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#

LimitValue
Items in an array, a map or a matrix100,000
Characters in a text one call builds1,000,000
Characters in a text of a drawing or a cell2,000 (cut, with a warning)
A pattern of text.match: characters, instructions once repeats are written out, a repeat count256, 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#

LimitValue
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 go2,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#

LimitValue
Lines, labels and boxes kept when the header says nothing50
Most you may ask for with max_lines, max_labels, max_boxes500
Most for max_polylines100
A table: columns, rows, cells100, 500, 10,000
Cells of all live tables together20,000
Tables kept40

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.

LimitValue
Times a script may ring on one bar20
Times it may ring in one run5,000
Characters in an alert message4,096 (cut, with a warning)

Requests and modules#

LimitValue
Different symbol-and-timeframe pairs a chart script may read20
Modules importing modules, deep8
Imports compiled for one script64
Characters of module text compiled for one script1,000,000
Periods prior() may go back64

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, bind and secret inputs.
  • The blocks on close and on tick, the report statement and the bracket order statement; these belong to a later edition.
  • funding and hedge in 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.* and contract.*.
  • Items of a list written items[i] (use items.at(i)) and the selectors on lists such as .where(...) and .count(...).
  • The helpers pips(x) and to_ticks(d); multiply by symbol.pip or divide by symbol.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.