Reference
Reference: errors
In the StrateScript panel, an error appears in a red box under the editor:
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.
- E0xx and E1xx are syntax errors: the script cannot be read.
- E9xx are found while the script runs. The built-in check runs the script on a short synthetic market, so most of them are found before the script reaches the chart. An error in a branch that never runs there appears on the chart when that line first runs.
While an error remains, the script does not run, and the chart keeps its last valid result.
Lexical errors (E0xx)#
| Code | Message | Cause and fix |
|---|---|---|
| E000 | Strate engine unreachable | Not an error in your script: the app could not reach its script engine, so nothing was checked. Run the script again. |
| E001 | unclosed /* comment | Close the comment with */. |
| E002 | unclosed string | A string is missing its closing ", or spans a line break. Strings stay on one line; use \n for a line break. |
| E003 | invalid color: write #RRGGBB or #RRGGBBAA | Use 6 or 8 hexadecimal digits. |
| E004 | unknown suffix attached to a number | 4ticks: write 4 ticks with a space. Duration units (ns us ms s m h d w) are the only suffixes written without a space. |
| E005 | non-ASCII identifier: names are in English, without accents | Rename the variable with ASCII letters. |
| E006 | unexpected character 'x' | A character the language does not use, such as $, …, → or '. |
Syntax errors (E1xx)#
| Code | Message | Cause and fix |
|---|---|---|
| E100 | expected "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. |
| E101 | expected a name | A name was expected (after fn, type, as…). |
| E102 | expected a string | The header has no name: strategy "My strategy" { … }. |
| E103 | expected 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). |
| E104 | a single header, placed before the statements | Move the header to the top, or remove the second one. |
| E105 | expected a setting "name: value" | In a header, an object or an import override, each entry is name: value. |
| E106 | expected "," or ")" | A missing comma (ema(close 20), corrected by Fix), or a unit word after a variable (n ticks: write price(n)). |
| E107 | a type name starts with an uppercase letter | type Zone { … }, not type zone. |
| E108 | a pattern has exactly one "when" clause | Add the missing when, or merge two into one with and. |
| E109 | "x" needs an initial value | var x = 0. Fix adds = 0. |
| E110 | missing "}" | Close the block. |
| E111 | "x" is only allowed at the top level of the script | indicator, strategy, research, import, on, pattern, type, enum, method inside a block or a function. Move it to the top level. |
| E112 | cannot assign to this expression | The left side of = must be a variable, a field of your own type, or a list/map element. |
| E113 | expected ":" in the conditional a ? b : c | Complete the conditional. |
| E114 | chained comparisons are not allowed: write a < b and b < c | |
| E115 | positional argument after a named argument | Put positional arguments first (Fix does it). |
| E116 | expected an expression | Something is missing, or a reserved word is used as a name (in = 3), or .5 instead of 0.5. |
| E117 | nested more than 200 levels deep | Split the expression or the blocks. |
| E199 | unexpected declaration | A declaration where it is not allowed. |
Run-time errors (E9xx)#
| Code | Message (or its beginning) | Cause and fix |
|---|---|---|
| E901 | unknown 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:. |
| E902 | script too slow: more than N operations on bar i | The 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 script | Move the declaration out of the block or function. |
| E904 | invalid 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 defined | x += 1 on a name never declared. Declare it first: x = 0. |
| E906 | loop over 10,000 iterations | Reduce the range, or restructure the loop. |
| E907 | for … in expects a range (a..b), a list, a map or a ring | |
| E908 | a X has no fields (".y") | Reading a field on a number, text, na… |
| E909 | "x" is a const: it cannot be changed | Declare it with var. |
| E910 | "-" expects a number | |
| E911 | [-1] reads the future | Use [1] (Fix does it). Also: bar.footprint read inside a handler, pattern or clock. |
| E912 | history [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]. |
| E913 | unsupported call form | Calling something that is not a function in this way. |
| E914 | more than 64 nested calls | Recursion too deep: at most 65 nested calls (a recursive f(64) that goes down to f(0) works; f(65) fails). |
| E915 | missing argument "p" for f() | Pass the argument or give the parameter a default. |
| E916 | unknown 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 times | An 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.) |
| E921 | cannot add a string and a X | Convert first: "n=" + str(n). |
| E922 | "op" does not apply to X and Y | e.g. a duration compared with a number other than 0: write the number as a duration (5s), or divide the duration (d / 1s). |
| E923 | length must be a whole number ≥ 1 | A length below 1 or na in sma, ema, highest, stats.*… A fractional length ≥ 1 is rounded, not refused. |
| E924 | f() needs at least one value | max() or min() with no argument. |
| E925 | settings or time ranges | input.* 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. |
| E926 | fill() takes two plots, or a plot and a value | p1 = plot(…), then fill(p1, p2, color) or fill(p1, 0, color). |
| E927 | marker or cell option | A shape:, location:, size: outside the allowed lists; location: "price" without price:; cell(…, side:) other than left/right/full. |
| E928 | colors, objects, tables | alpha/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 defined | A name that does not exist, or a variable created inside a block and read outside it. Sometimes with "did you mean …". |
| E931 | unknown 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. |
| E933 | unknown method, or invalid argument | An 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). |
| E934 | patterns and signals | Missing 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. |
| E935 | clocks, 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. |
| E936 | request(), 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. |
| E937 | imports, 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. |
| E938 | research, indexes | study, report, compare outside a research script, or with invalid arguments; a list index out of range or not a number. |
| E939 | strategies, map keys | Missing 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. |
| E940 | ring(n) keeps the last n values: n from 1 to 1,000,000 / window(duration) … | |
| E941 | collection larger than 1,000,000 elements | |
| E942 | invalid header value | min/max, format, precision, labels, visible_on, initial_balance, level_history, flow_history, mbo_from, book_from, mbo_max. The message says what is expected. |
| E943 | persist | persist outside a named indicator, or holding something that cannot be kept (a drawing, a function…). Use var, or keep data only. |
| E944 | the bar of … holds more than N MBO events | One bar not yet closed holds more order-by-order events (or book snapshots) than allowed: use a shorter timeframe, or raise mbo_max:. |
| E945 | N bars sent, at most 50000 per script | Shorten the chart history or use a higher timeframe. |
| E948 | overlay / pane | A 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. |
| E950 | script longer than 200,000 characters | |
| E960 | (long backtest) a day could not be read | e.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: message | The script failed on that day; the message is the underlying error. |
| E999 | internal error | The 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 -->
indicator "My average" { overlay: true }
length = input.int("Length", 20)
plot(sma(close, lenght))<!-- expect: E930 -->
if close > open { up = close }
plot(up)<!-- expect: E911 -->
plot(close[-1])<!-- expect: E912 -->
plot((close + 1)[1])<!-- expect: E921 -->
print("close = " + close)<!-- expect: E922 -->
d = bar.close_time - bar.time
if d > 60 { print("long bar") }<!-- expect: E909 -->
const k = 2
k = 3<!-- expect: E905 -->
total += volume<!-- expect: E004 -->
plot(close + 4ticks)<!-- expect: E106 -->
n = input.int("Offset", 4)
plot(close + n ticks)<!-- expect: E114 -->
plot(low < close < high ? 1 : 0)<!-- expect: E939 -->
strategy "No costs" { overlay: true }
if close > open { enter("buy", stop: 8 ticks) }<!-- expect: E939 -->
indicator "Not a strategy"
if close > open { enter("buy") }<!-- expect: E938 -->
indicator "Not research"
pattern "Up" {
on: bar
side: "buy"
when close > open
}
on signal(s) { study(s) }<!-- expect: E942 -->
indicator "Bad history" { level_history: 45m }
plot(close)<!-- expect: E933 -->
indicator "Window too long" { overlay: false }
lv = mbo.level(close, window: 3m)
plot(nz(lv.added))<!-- expect: E911 -->
indicator "Footprint in a handler"
on trade(t) { fp = bar.footprint }<!-- expect: E948 -->
indicator "Price script" { overlay: true }
plot(volume, overlay: false)<!-- expect: E943 -->
strategy "No persist" { overlay: true, costs: { commission: 2.5 usd, slippage: 1 tick } }
persist n = 0<!-- expect: E934 -->
indicator "Typo in pattern"
pattern "P" {
on: bar
group: "x"
when close > open
}<!-- expect: E935 -->
indicator "No such clock"
on clock fast { print("tick") }<!-- expect: E937 -->
indicator "Bad import"
import "strate/patterns/absorption_held_volume" as a { minVolume: 90 }