Reference

Reference: errors

In the StrateScript panel, an error appears in a red box under the editor:

Text
Line 3 · "clsoe" is not defined
Did you mean "close"?

The first line gives the line number and the message; the second, when one exists, a suggested fix. Hover the box's title to see the error code and the column (E930 · column 10). Some errors also come with a one-click Fix: a "did you mean" correction, a negative history index (close[-1] → close[1]), if a = b (→ ==), a missing comma, and a positional argument placed after a named one.

While an error remains, the script does not run, and the chart keeps its last valid result.

Lexical errors (E0xx)#

CodeMessageCause and fix
E000Strate engine unreachableNot an error in your script: the app could not reach its script engine, so nothing was checked. Run the script again.
E001unclosed /* commentClose the comment with */.
E002unclosed stringA string is missing its closing ", or spans a line break. Strings stay on one line; use \n for a line break.
E003invalid color: write #RRGGBB or #RRGGBBAAUse 6 or 8 hexadecimal digits.
E004unknown suffix attached to a number4ticks: write 4 ticks with a space. Duration units (ns us ms s m h d w) are the only suffixes written without a space.
E005non-ASCII identifier: names are in English, without accentsRename the variable with ASCII letters.
E006unexpected character 'x'A character the language does not use, such as $, …, → or '.

Syntax errors (E1xx)#

CodeMessageCause and fix
E100expected "x"A symbol is missing. if a = b { is corrected to ==. Also raised for a fn declared inside a block: declare functions at the top level.
E101expected a nameA name was expected (after fn, type, as…).
E102expected a stringThe header has no name: strategy "My strategy" { … }.
E103expected end of statement (new line or ";")Two statements on one line, an unknown word at the start of a line (study "X"), 5 m with a space, or a type annotation without var (x: int = 3).
E104a single header, placed before the statementsMove the header to the top, or remove the second one.
E105expected a setting "name: value"In a header, an object or an import override, each entry is name: value.
E106expected "," or ")"A missing comma (ema(close 20), corrected by Fix), or a unit word after a variable (n ticks: write price(n)).
E107a type name starts with an uppercase lettertype Zone { … }, not type zone.
E108a pattern has exactly one "when" clauseAdd the missing when, or merge two into one with and.
E109"x" needs an initial valuevar x = 0. Fix adds = 0.
E110missing "}"Close the block.
E111"x" is only allowed at the top level of the scriptindicator, strategy, research, import, on, pattern, type, enum, method inside a block or a function. Move it to the top level.
E112cannot assign to this expressionThe left side of = must be a variable, a field of your own type, or a list/map element.
E113expected ":" in the conditional a ? b : cComplete the conditional.
E114chained comparisons are not allowed: write a < b and b < c
E115positional argument after a named argumentPut positional arguments first (Fix does it).
E116expected an expressionSomething is missing, or a reserved word is used as a name (in = 3), or .5 instead of 0.5.
E117nested more than 200 levels deepSplit the expression or the blocks.
E199unexpected declarationA declaration where it is not allowed.

Run-time errors (E9xx)#

CodeMessage (or its beginning)Cause and fix
E901unknown event "x" (available: on trade(t), on book(b), on order(o), on match(m), on session(s), on signal(s from "…"), on clock name)Use one of the listed events. Also raised for: a date used as a value, a range a..b outside for, when(…) outside a clock, set<…>, heap<…>, deque<…>, series<…>, and the pattern setting expire:.
E902script too slow: more than N operations on bar iThe budget per bar or per event is exceeded. Reduce loop sizes, or raise it in the header: budget: 5000000 (at most 20,000,000). Also raised for an invalid budget: value.
E903"var", "state", "const" and "persist" are declared at the top level of the scriptMove the declaration out of the block or function.
E904invalid assignment or loop[…] = on something that is not a list, map or ring; assigning a field of a built-in object; for i, x in on a value that has no index; more than two loop names.
E905"x" is not definedx += 1 on a name never declared. Declare it first: x = 0.
E906loop over 10,000 iterationsReduce the range, or restructure the loop.
E907for … in expects a range (a..b), a list, a map or a ring
E908a X has no fields (".y")Reading a field on a number, text, na…
E909"x" is a const: it cannot be changedDeclare it with var.
E910"-" expects a number
E911[-1] reads the futureUse [1] (Fix does it). Also: bar.footprint read inside a handler, pattern or clock.
E912history [n] applies to a variable or a built-in series(close + 1)[1] or [n] on a function's local: assign the expression to a top-level variable, then use variable[n].
E913unsupported call formCalling something that is not a function in this way.
E914more than 64 nested callsRecursion too deep: at most 65 nested calls (a recursive f(64) that goes down to f(0) works; f(65) fails).
E915missing argument "p" for f()Pass the argument or give the parameter a default.
E916unknown type "T"Declare it: type T { field: float }. Also for method T.name without type T.
E917"self" is only defined inside a method
E920"op" does not apply to strings / to two durations / to two timesAn operator that does not apply: between two texts (only + and comparisons do), two durations (only +, -, / and comparisons), two times (only - and comparisons), or a time and a duration (only + and -). E.g. "a" - "b", 5s * 5s, bar.time + bar.time. ("a" * 2 gives E922.)
E921cannot add a string and a XConvert first: "n=" + str(n).
E922"op" does not apply to X and Ye.g. a duration compared with a number other than 0: write the number as a duration (5s), or divide the duration (d / 1s).
E923length must be a whole number ≥ 1A length below 1 or na in sma, ema, highest, stats.*… A fractional length ≥ 1 is rounded, not refused.
E924f() needs at least one valuemax() or min() with no argument.
E925settings or time rangesinput.* without a title; input.choice without a list; invalid input.session default or session.in range (write "HHMM-HHMM" in New York time); input.price/input.time default of the wrong type.
E926fill() takes two plots, or a plot and a valuep1 = plot(…), then fill(p1, p2, color) or fill(p1, 0, color).
E927marker or cell optionA shape:, location:, size: outside the allowed lists; location: "price" without price:; cell(…, side:) other than left/right/full.
E928colors, objects, tablesalpha/mix on a non-color; a time or price of the wrong type for line.new, box.new, label.new; table position, size, cell outside the table, align.
E930"x" is not definedA name that does not exist, or a variable created inside a block and read outside it. Sometimes with "did you mean …".
E931unknown function "f"A function that does not exist. Check Reference: functions.
E932"x" is not a field of … (fields: …)An unknown field of a library object or of your own type; the message lists the valid fields.
E933unknown method, or invalid argumentAn unknown method; a bad argument of norm.*, of.*, mbo.*, book.depth, stats.percentile, fp.imbalances; a window longer than level_history: or flow_history: (the message gives the header line to add).
E934patterns and signalsMissing or unknown on:; unknown pattern setting; two patterns with the same name; on signal(s from "X") with no pattern X; bad side:, cooldown: or confirm:; acc.add() of something that is not a footprint.
E935clocks, rows()Unknown clock kind, two clocks with the same name, on clock x without a clock x, a non-positive threshold; fp.rows(n) with n < 1.
E936request(), col:Wrong arguments, unknown timeframe, timeframe not a multiple of the chart's, drawing or session levels inside request, no bars for the symbol; cell(…, col:) out of range.
E937imports, align:Import not found, two imports with the same alias, an imported script that imports, an override the import does not declare; draw.text(…, align:) other than left/center/right.
E938research, indexesstudy, report, compare outside a research script, or with invalid arguments; a list index out of range or not a number.
E939strategies, map keysMissing or invalid costs:, fill_model:, latency:; enter, exit, cancel, position, on fill, on exit outside a strategy; invalid enter side, type, missing price:, non-positive distances, non-duration timeouts; a map key that is not a number, text or bool.
E940ring(n) keeps the last n values: n from 1 to 1,000,000 / window(duration) …
E941collection larger than 1,000,000 elements
E942invalid header valuemin/max, format, precision, labels, visible_on, initial_balance, level_history, flow_history, mbo_from, book_from, mbo_max. The message says what is expected.
E943persistpersist outside a named indicator, or holding something that cannot be kept (a drawing, a function…). Use var, or keep data only.
E944the bar of … holds more than N MBO eventsOne bar not yet closed holds more order-by-order events (or book snapshots) than allowed: use a shorter timeframe, or raise mbo_max:.
E945N bars sent, at most 50000 per scriptShorten the chart history or use a higher timeframe.
E948overlay / paneA pane element drawn from a price script, overlay: and pane: that disagree, an element that cannot leave its pane, or a fill between two places.
E950script longer than 200,000 characters
E960(long backtest) a day could not be reade.g. too many bars or order-by-order events in one day: use a larger timeframe or a narrower hours window.
E961(long backtest) YYYY-MM-DD: line N: messageThe script failed on that day; the message is the underlying error.
E999internal errorThe engine did not answer in time, or data arrived late twice in a row: try again.

Examples#

Each example below fails with the code shown above it, exactly as written.

<!-- expect: E930 -->

StrateScript
indicator "My average" { overlay: true }
length = input.int("Length", 20)
plot(sma(close, lenght))

<!-- expect: E930 -->

StrateScript
if close > open { up = close }
plot(up)

<!-- expect: E911 -->

StrateScript
plot(close[-1])

<!-- expect: E912 -->

StrateScript
plot((close + 1)[1])

<!-- expect: E921 -->

StrateScript
print("close = " + close)

<!-- expect: E922 -->

StrateScript
d = bar.close_time - bar.time
if d > 60 { print("long bar") }

<!-- expect: E909 -->

StrateScript
const k = 2
k = 3

<!-- expect: E905 -->

StrateScript
total += volume

<!-- expect: E004 -->

StrateScript
plot(close + 4ticks)

<!-- expect: E106 -->

StrateScript
n = input.int("Offset", 4)
plot(close + n ticks)

<!-- expect: E114 -->

StrateScript
plot(low < close < high ? 1 : 0)

<!-- expect: E939 -->

StrateScript
strategy "No costs" { overlay: true }
if close > open { enter("buy", stop: 8 ticks) }

<!-- expect: E939 -->

StrateScript
indicator "Not a strategy"
if close > open { enter("buy") }

<!-- expect: E938 -->

StrateScript
indicator "Not research"
pattern "Up" {
  on: bar
  side: "buy"
  when close > open
}
on signal(s) { study(s) }

<!-- expect: E942 -->

StrateScript
indicator "Bad history" { level_history: 45m }
plot(close)

<!-- expect: E933 -->

StrateScript
indicator "Window too long" { overlay: false }
lv = mbo.level(close, window: 3m)
plot(nz(lv.added))

<!-- expect: E911 -->

StrateScript
indicator "Footprint in a handler"
on trade(t) { fp = bar.footprint }

<!-- expect: E948 -->

StrateScript
indicator "Price script" { overlay: true }
plot(volume, overlay: false)

<!-- expect: E943 -->

StrateScript
strategy "No persist" { overlay: true, costs: { commission: 2.5 usd, slippage: 1 tick } }
persist n = 0

<!-- expect: E934 -->

StrateScript
indicator "Typo in pattern"
pattern "P" {
  on: bar
  group: "x"
  when close > open
}

<!-- expect: E935 -->

StrateScript
indicator "No such clock"
on clock fast { print("tick") }

<!-- expect: E937 -->

StrateScript
indicator "Bad import"
import "strate/patterns/absorption_held_volume" as a { minVolume: 90 }
STRATE / PRODUCT SCREENSHOT

Actual platform screenshot.