{
  "catalogue": "openscript-errors",
  "schemaVersion": 1,
  "languageVersion": 1,
  "placeholderSyntax": "{name}",
  "severities": {
    "error": "Stops compilation, or stops the bar. Nothing is drawn from a bar that raised one.",
    "warning": "Never stops anything. Reported on the line and in the editor's gutter."
  },
  "stages": {
    "lex": "Reading characters into tokens.",
    "parse": "Reading tokens into a tree.",
    "check": "Names, types, scope and call sites, before any bar runs.",
    "runtime": "Executing a bar.",
    "host": "The host answering the engine: data, limits and order destinations.",
    "import": "Reading a script written in another chart language and writing it as OpenScript."
  },
  "stageLabels": {
    "lex": "lexer",
    "parse": "parser",
    "check": "checker",
    "runtime": "engine",
    "host": "host",
    "import": "importer"
  },
  "ranges": [
    {
      "prefix": "OS1",
      "kind": "Syntax",
      "means": "The source text is not a program: characters, layout and grammar.",
      "severity": "error"
    },
    {
      "prefix": "OS2",
      "kind": "Names and types",
      "means": "The program parses, and a name or a type does not work out.",
      "severity": "error"
    },
    {
      "prefix": "OS3",
      "kind": "Arguments",
      "means": "A call or an option is wrong at the call site.",
      "severity": "error"
    },
    {
      "prefix": "OS4",
      "kind": "Runtime",
      "means": "A bar produced a value the engine cannot act on.",
      "severity": "error"
    },
    {
      "prefix": "OS5",
      "kind": "Limits",
      "means": "A budget was exhausted: loops, memory, size or time.",
      "severity": "error"
    },
    {
      "prefix": "OS6",
      "kind": "Data",
      "means": "Bars, instruments, timeframes and the host's answers to requests.",
      "severity": "error"
    },
    {
      "prefix": "OS7",
      "kind": "Orders",
      "means": "An order could not be placed as written.",
      "severity": "error"
    },
    {
      "prefix": "OS8",
      "kind": "Warnings",
      "means": "The script compiles and runs, and something in it is probably not meant.",
      "severity": "warning"
    },
    {
      "prefix": "OS9",
      "kind": "Import",
      "means": "A script written in another chart language could not be translated as written, or was translated with a stated difference.",
      "severity": "error or warning"
    }
  ],
  "entries": [
    {
      "code": "OS1001",
      "title": "Unexpected character",
      "severity": "error",
      "stage": "lex",
      "since": 1,
      "message": "Unexpected character {char}. {suggestion}",
      "placeholders": {
        "char": "the offending character, quoted, with its Unicode name when it is not an ASCII graphic",
        "suggestion": "the replacement sentence for this character, from the substitution table in section 7 of this document"
      },
      "cause": "Outside a string literal the language accepts ASCII letters, ASCII digits, space, newline and the punctuation list of language.md 3.12, and nothing else. A non-breaking space pasted from a web page, a typographic quotation mark pasted from a word processor, a non-ASCII letter in a name, and an operator the language does not have (!, &&, ||, ^, {, }) all arrive here. The character is rejected where it sits rather than three tokens later, because an invisible character produces a baffling parse error otherwise. Two runs whose every character is legal are not this code: a name written against a number is OS1029, and a colour literal with the wrong number of digits is OS1027. Naming one character of either and advising its deletion, which is what this fix says to do, would leave a program that still compiles and means something else.",
      "fix": "Delete the character or replace it with the plain ASCII spelling the message names: a plain space for a non-breaking space, a straight quote for a typographic one, not for !, and for &&, or for ||, pow(a, b) for ^.",
      "autofix": true,
      "example": {
        "before": "if !ready\n    signal(\"BUY\")",
        "after": "if not ready\n    signal(\"BUY\")"
      },
      "spec": "language.md 3.1, 3.3, 3.12",
      "refines": null,
      "test": "tests/examples/rejected/OS1001.oscript"
    },
    {
      "code": "OS1002",
      "title": "Tab in indentation",
      "severity": "error",
      "stage": "lex",
      "since": 1,
      "message": "This line is indented with a tab.",
      "placeholders": {},
      "cause": "Leading whitespace is spaces only. A tab is rejected rather than expanded because the width of a tab is an editor setting, so a file whose block structure depends on it means something different when someone else opens it.",
      "fix": "Replace the leading tabs with spaces. Four spaces per level is the convention and the formatter's output.",
      "autofix": true,
      "example": {
        "before": "if close > open\n\tsignal(\"UP\")",
        "after": "if close > open\n    signal(\"UP\")"
      },
      "spec": "language.md 3.10",
      "refines": null,
      "test": "tests/examples/rejected/OS1002.oscript"
    },
    {
      "code": "OS1003",
      "title": "Indentation does not match this block",
      "severity": "error",
      "stage": "lex",
      "since": 1,
      "message": "This line is indented {found} spaces; the block opened at line {line} is indented {expected}.",
      "placeholders": {
        "found": "the leading space count on this line",
        "expected": "the leading space count every line of this block carries",
        "line": "the line that opened the block"
      },
      "cause": "Every line of one block carries exactly the same leading whitespace. A difference of one space is still a difference, because the alternative is a language where a block's extent depends on a tolerance nobody can see. A blank line and a comment-only line stand outside the rule: they carry no token and no indentation at all, so any leading whitespace is accepted on them and neither one is ever this error. A continuation line stands outside it for a different reason: it belongs to a statement that began above it and opens no block, so what its indentation has to clear is that statement rather than a block, and that is OS1028.",
      "fix": "Indent this line to {expected} spaces to keep it in the block, or to {line}'s own indentation to end the block here.",
      "autofix": true,
      "example": {
        "before": "if trending\n    body = close - open\n     wick = high - low",
        "after": "if trending\n    body = close - open\n    wick = high - low"
      },
      "spec": "language.md 3.10",
      "refines": null,
      "test": "tests/examples/rejected/OS1003.oscript"
    },
    {
      "code": "OS1004",
      "title": "Unterminated string literal",
      "severity": "error",
      "stage": "lex",
      "since": 1,
      "message": "This string literal opens with {quote} and the line ends before a matching {quote}.",
      "placeholders": {
        "quote": "the opening delimiter, a double or a single quote"
      },
      "cause": "A string literal may not span a line, so the scanner reports the opening quote rather than swallowing the rest of the file and complaining about the last line.",
      "fix": "Close the string with a matching {quote} before the end of the line, and join text across lines with + and a continuation.",
      "autofix": false,
      "example": {
        "before": "signal(\"BUY)",
        "after": "signal(\"BUY\")"
      },
      "spec": "language.md 3.6",
      "refines": null,
      "test": "tests/examples/rejected/OS1004.oscript"
    },
    {
      "code": "OS1005",
      "title": "Unknown escape sequence",
      "severity": "error",
      "stage": "lex",
      "since": 1,
      "message": "{sequence} is not an escape sequence.",
      "placeholders": {
        "sequence": "the backslash and the character that followed it"
      },
      "cause": "The escapes are a backslash followed by one of \\ \" ' n t r 0, and uXXXX with exactly four hexadecimal digits. Anything else is almost always a Windows path or a regular expression that was pasted without doubling its backslashes.",
      "fix": "Double the backslash to write one literally, or use one of the escapes the language defines.",
      "autofix": true,
      "example": {
        "before": "path = \"C:\\data\\bars\"",
        "after": "path = \"C:\\\\data\\\\bars\""
      },
      "spec": "language.md 3.6",
      "refines": "OS1004",
      "test": "tests/examples/rejected/OS1005.oscript"
    },
    {
      "code": "OS1006",
      "title": "Assignment used as a condition",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "= assigns a value, and a condition needs a comparison.",
      "placeholders": {},
      "cause": "Assignment is a statement and never an expression, so the classic typo cannot compile into a condition that is always true. There is no form of this language in which if x = 5 means anything.",
      "fix": "Write == to compare, or move the assignment to its own line above the if.",
      "autofix": true,
      "example": {
        "before": "if len = 14\n    signal(\"DEFAULT\")",
        "after": "if len == 14\n    signal(\"DEFAULT\")"
      },
      "spec": "language.md 10.1",
      "refines": null,
      "test": "tests/examples/rejected/OS1006.oscript"
    },
    {
      "code": "OS1007",
      "title": "Semicolon",
      "severity": "error",
      "stage": "lex",
      "since": 1,
      "message": "; is not part of the language.",
      "placeholders": {},
      "cause": "A statement ends at the end of its line and a line holds at most one statement, so there is no separator to write.",
      "fix": "Delete the ; and put the second statement on its own line.",
      "autofix": true,
      "example": {
        "before": "fast = ema(close, 9); slow = ema(close, 21)",
        "after": "fast = ema(close, 9)\nslow = ema(close, 21)"
      },
      "spec": "language.md 3.10",
      "refines": null,
      "test": "tests/examples/rejected/OS1007.oscript"
    },
    {
      "code": "OS1008",
      "title": "Chained comparison",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "A comparison cannot be chained: {op1} is already applied before {op2}.",
      "placeholders": {
        "op1": "the first comparison operator on the line",
        "op2": "the second comparison operator on the line"
      },
      "cause": "Two readings of a < b < c are plausible to a reader, the mathematical one and the C-family one, and a form with two plausible meanings has no place in a language that places orders. The grammar allows at most one comparison operator per expression.",
      "fix": "Split it with and, naming the middle value twice: a < b and b < c.",
      "autofix": false,
      "example": {
        "before": "if 30 < r < 70\n    zone = \"mid\"",
        "after": "if 30 < r and r < 70\n    zone = \"mid\""
      },
      "spec": "language.md 9.3",
      "refines": null,
      "test": "tests/examples/rejected/OS1008.oscript"
    },
    {
      "code": "OS1009",
      "title": "break or continue outside a loop",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "{word} is only valid inside a for or a while body.",
      "placeholders": {
        "word": "break or continue, whichever was written"
      },
      "cause": "break leaves the innermost loop and continue starts its next iteration, so neither has a meaning where there is no loop to act on.",
      "fix": "Move it inside the loop body, or write return to leave a function early.",
      "autofix": false,
      "example": {
        "before": "fn firstAbove(values, mark) =>\n    if size(values) == 0\n        break\n    values[0]",
        "after": "fn firstAbove(values, mark) =>\n    if size(values) == 0\n        return none\n    values[0]"
      },
      "spec": "language.md 10.5",
      "refines": null,
      "test": "tests/examples/rejected/OS1009.oscript"
    },
    {
      "code": "OS1010",
      "title": "Block header with no body",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "{header} opens a block, and the next line is not indented more deeply.",
      "placeholders": {
        "header": "the keyword that opened the block, such as if, else, for, while, case or default"
      },
      "cause": "A header line introduces a block that consists of the following lines indented more deeply than the header. With nothing indented under it the header has no body, which is almost always a line that lost its indentation in a paste. Blank and comment-only lines carry no token, so they never count as a body: a header followed only by those, and then by a line at or left of the header, is still this error.",
      "fix": "Indent the body under the header, or delete the header line if the body is genuinely empty.",
      "autofix": true,
      "example": {
        "before": "if crossUp(fast, slow)\nsignal(\"BUY\")",
        "after": "if crossUp(fast, slow)\n    signal(\"BUY\")"
      },
      "spec": "language.md 3.10",
      "refines": null,
      "test": "tests/examples/rejected/OS1010.oscript"
    },
    {
      "code": "OS1011",
      "title": "var with no initial value",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "var {name} has no initial value.",
      "placeholders": {
        "name": "the name being declared"
      },
      "cause": "The declaration and the first assignment are one statement, so a persistent value always has something in it and no bar can read it before it exists.",
      "fix": "Give it a starting value; var {name} = none is the empty start.",
      "autofix": true,
      "example": {
        "before": "var runningHigh\nif high > orElse(runningHigh, high)\n    runningHigh = high",
        "after": "var runningHigh = none\nif isNone(runningHigh) or high > runningHigh\n    runningHigh = high"
      },
      "spec": "language.md 8.2",
      "refines": null,
      "test": "tests/examples/rejected/OS1011.oscript"
    },
    {
      "code": "OS1012",
      "title": "Bracket is never closed",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "The {bracket} opened at line {line} is never closed.",
      "placeholders": {
        "bracket": "the opening bracket character",
        "line": "the line the bracket was opened on"
      },
      "cause": "An open ( or [ continues the statement onto the following lines, so a missing closer makes the scanner read the rest of the file as one statement. The error is reported at the opening bracket, which is where the mistake is.",
      "fix": "Add the matching closer at the end of the argument list on line {line}.",
      "autofix": false,
      "example": {
        "before": "plot(ema(close, 9), \"EMA\", aqua",
        "after": "plot(ema(close, 9), \"EMA\", aqua)"
      },
      "spec": "language.md 3.11",
      "refines": null,
      "test": "tests/examples/rejected/OS1012.oscript"
    },
    {
      "code": "OS1013",
      "title": "Mismatched closing bracket",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "Found {found} where {expected} was expected, closing the {opener} opened at line {line}.",
      "placeholders": {
        "found": "the closing bracket that was written",
        "expected": "the closing bracket the opener requires",
        "opener": "the opening bracket character",
        "line": "the line the bracket was opened on"
      },
      "cause": "Brackets nest, and a call closes with ) while an index or an array literal closes with ].",
      "fix": "Change {found} to {expected}, which is what closes the {opener} opened at line {line}.",
      "autofix": true,
      "example": {
        "before": "total = sum(closes]",
        "after": "total = sum(closes)"
      },
      "spec": "language.md 19",
      "refines": null,
      "test": "tests/examples/rejected/OS1013.oscript"
    },
    {
      "code": "OS1014",
      "title": "Missing comma between arguments",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "Two arguments run together; a comma is missing before {token}.",
      "placeholders": {
        "token": "the first token of the second argument"
      },
      "cause": "Arguments are separated by commas. Two expressions side by side inside a call are not a form the language has, so the missing comma is reported rather than guessed at.",
      "fix": "Put a comma between the two arguments.",
      "autofix": true,
      "example": {
        "before": "plot(ema(close, 9) \"EMA\", aqua)",
        "after": "plot(ema(close, 9), \"EMA\", aqua)"
      },
      "spec": "language.md 11.2",
      "refines": null,
      "test": "tests/examples/rejected/OS1014.oscript"
    },
    {
      "code": "OS1015",
      "title": "Ternary with no second arm",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "This ? has no matching :",
      "placeholders": {},
      "cause": "The ternary always yields a value, so both arms are required. A ternary with one arm is usually a plot that wanted to draw nothing on some bars.",
      "fix": "Give the ternary both arms, and use none for the arm that should draw nothing.",
      "autofix": false,
      "example": {
        "before": "plot(ready ? value, \"Value\", aqua)",
        "after": "plot(ready ? value : none, \"Value\", aqua)"
      },
      "spec": "language.md 9.5",
      "refines": null,
      "test": "tests/examples/rejected/OS1015.oscript"
    },
    {
      "code": "OS1016",
      "title": "else does not follow an if",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "This else is indented {found} spaces and the nearest if is indented {expected}.",
      "placeholders": {
        "found": "the leading space count on the else line",
        "expected": "the leading space count of the if it should pair with"
      },
      "cause": "An else pairs with the if at its own indentation. At any other indentation there is no if for it to belong to, and guessing which one was meant would make the block structure unreadable.",
      "fix": "Line the else up with its if, at {expected} spaces.",
      "autofix": true,
      "example": {
        "before": "if trending\n    signal(\"BUY\")\n  else\n    signal(\"WAIT\")",
        "after": "if trending\n    signal(\"BUY\")\nelse\n    signal(\"WAIT\")"
      },
      "spec": "language.md 10.2",
      "refines": null,
      "test": "tests/examples/rejected/OS1016.oscript"
    },
    {
      "code": "OS1017",
      "title": "case or default in the wrong place",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "{word} is only valid inside a switch, and default must be its last arm.",
      "placeholders": {
        "word": "case or default, whichever was written"
      },
      "cause": "The arms of a switch are its whole body. A default that is not last would leave the arms after it unreachable, which the language rejects rather than silently accepts.",
      "fix": "Move the arm inside the switch block, and put default after every case.",
      "autofix": false,
      "example": {
        "before": "switch method\n    default\n        len = 14\n    case \"fast\"\n        len = 9",
        "after": "switch method\n    case \"fast\"\n        len = 9\n    default\n        len = 14"
      },
      "spec": "language.md 10.6",
      "refines": null,
      "test": "tests/examples/rejected/OS1017.oscript"
    },
    {
      "code": "OS1018",
      "title": "More than one statement on a line",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "Unexpected {token} after the end of this statement.",
      "placeholders": {
        "token": "the first token that follows the complete statement"
      },
      "cause": "A line holds at most one statement, so anything after a statement ends is either a missing operator or a second statement that lost its newline. An assignment operator after an index or after a dotted name is not this error: the statement did not end there, and what is wrong is the target rather than anything following it. Those two are OS1024 and OS1025.",
      "fix": "Put {token} and what follows it on its own line, or supply the operator that was meant to join them.",
      "autofix": false,
      "example": {
        "before": "fast = ema(close, 9) slow = ema(close, 21)",
        "after": "fast = ema(close, 9)\nslow = ema(close, 21)"
      },
      "spec": "language.md 3.10",
      "refines": null,
      "test": "tests/examples/rejected/OS1018.oscript"
    },
    {
      "code": "OS1019",
      "title": "Reserved word used as a name",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "{word} is a reserved word and cannot be used as a name.",
      "placeholders": {
        "word": "the reserved word that was used as a name",
        "suggestion": "a near name that is not reserved, derived from the word"
      },
      "cause": "The reserved words of language.md 3.4 include five that version 1 does not implement (import, map, matrix, type, as). They are reserved now so that implementing them later cannot break a script that used one as a name. A named argument label is not a name: it is matched against the callee's parameter list and is never looked up in any scope, so plot(v, \"V\", color = aqua) is correct and is not this error. The rule stops at the label. A parameter of a user function is an ordinary identifier, because the body refers to it, so fn f(color = red) is this error.",
      "fix": "Rename it; {suggestion} keeps the meaning and is not reserved.",
      "autofix": false,
      "example": {
        "before": "type = input(\"fast\", \"Mode\", options = [\"fast\", \"slow\"])",
        "after": "mode = input(\"fast\", \"Mode\", options = [\"fast\", \"slow\"])"
      },
      "spec": "language.md 3.4",
      "refines": null,
      "test": "tests/examples/rejected/OS1019.oscript"
    },
    {
      "code": "OS1020",
      "title": "Incomplete for header",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "A for header needs = start to end or in array; found {token}.",
      "placeholders": {
        "token": "the token that appeared where to or in was expected"
      },
      "cause": "There are two loop forms and no third. A counted loop names a start and an end, and a loop over an array names the array.",
      "fix": "Write for i = 0 to size(values) - 1 for a counted loop, or for v in values to visit elements.",
      "autofix": false,
      "example": {
        "before": "for i = 0, 9\n    total += close[i]",
        "after": "for i = 0 to 9\n    total += close[i]"
      },
      "spec": "language.md 10.3",
      "refines": null,
      "test": "tests/examples/rejected/OS1020.oscript"
    },
    {
      "code": "OS1021",
      "title": "The version declaration is not first",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "version must be the first line that is not blank and not a comment; line {line} came before it.",
      "placeholders": {
        "line": "the line of the first statement that preceded the version declaration"
      },
      "cause": "A host reads the version with a one-line scan so it can pick a front end before any parsing happens. A declaration further down the file would be read by the wrong front end, which defeats the purpose of having one.",
      "fix": "Move the version line to the top of the file, above the study or strategy declaration.",
      "autofix": true,
      "example": {
        "before": "study(\"EMA cross\")\nversion 1",
        "after": "version 1\n\nstudy(\"EMA cross\")"
      },
      "spec": "language.md 4",
      "refines": null,
      "test": "tests/examples/rejected/OS1021.oscript"
    },
    {
      "code": "OS1022",
      "title": "Expression expected",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "An expression was expected after {token}.",
      "placeholders": {
        "token": "the operator or punctuation the statement ended on"
      },
      "cause": "An operator, a comma or an opening bracket at the end of a statement continues it onto the next line, so a statement that ends this way and is followed by nothing usable has lost its right-hand side.",
      "fix": "Supply the missing operand, or delete the trailing {token}.",
      "autofix": false,
      "example": {
        "before": "len = input(14, \"Length\") +",
        "after": "len = input(14, \"Length\")"
      },
      "spec": "language.md 3.11",
      "refines": null,
      "test": "tests/examples/rejected/OS1022.oscript"
    },
    {
      "code": "OS1023",
      "title": "A function declared inside a block",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "fn {name} is declared inside a block, and a function is declared at the top level of the file.",
      "placeholders": {
        "name": "the function being declared"
      },
      "cause": "Functions may not be nested (language.md 11.1). A declaration under an if, a loop, a switch arm or another function's body sits in a scope that ends where the block ends, so the name would exist for part of a file and not the rest, and a reader would have to trace the block structure to know whether a call on the line in front of them was legal. The declaration is reported rather than dropped or lifted: dropping it leaves every call to it as OS2001 with no word about where the function went, and lifting it to the top level compiles a form the language does not have.",
      "fix": "Move the whole declaration out to the top level of the file, and call {name} from inside the block.",
      "autofix": false,
      "example": {
        "before": "if trending\n    fn smoothed(src) => sma(src, 9)\n    plot(smoothed(close), \"Smooth\", aqua)",
        "after": "fn smoothed(src) => sma(src, 9)\n\nsmooth = smoothed(close)\nplot(trending ? smooth : none, \"Smooth\", aqua)"
      },
      "spec": "language.md 11.1",
      "refines": null,
      "test": "tests/examples/rejected/OS1023.oscript"
    },
    {
      "code": "OS1024",
      "title": "Assignment to an indexed element",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "An assignment writes to a name, and this target is an index into {name}.",
      "placeholders": {
        "name": "the name that was indexed"
      },
      "cause": "The grammar of language.md 19 admits one assignment target, an identifier, and there is no indexed assignment anywhere in the language. The reason is that [] reads two different things (language.md 9.6): on an array it is an element, which section 14.1 writes with set(arr, i, v), and on a series it is a bar the engine has already computed, which nothing in a script may overwrite. One syntax covering both would read as though a past bar could be rewritten.",
      "fix": "Change an array element with set({name}, i, v), or assign to a plain name: the past of a series is computed and never written.",
      "autofix": false,
      "example": {
        "before": "var prices = [0.0]\nprices[0] = close",
        "after": "var prices = [0.0]\nset(prices, 0, close)"
      },
      "spec": "language.md 9.6, 14.1, 19",
      "refines": null,
      "test": "tests/examples/rejected/OS1024.oscript"
    },
    {
      "code": "OS1025",
      "title": "Assignment to a member",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "An assignment writes to a name, and this target is the member {member} of {name}.",
      "placeholders": {
        "name": "the name written before the dot",
        "member": "the name written after the dot"
      },
      "cause": "The grammar of language.md 19 admits one assignment target, an identifier. A dotted name reads a member of one of the namespaces on the closed list in language.md 15.2, and every member on that list is a per-bar fact, an instrument fact, a position fact or a function, each of them produced by the engine or by the host. There is nothing behind a dot that a script owns. Version 1 has no user-declared types that could add one either: type is a reserved word and is not implemented (language.md 18). A dotted name whose first half is not a namespace is the same answer for a simpler reason: it has no members at all.",
      "fix": "Assign to a plain name. Version 1 has no member assignment: a dot reads a member, and the members a script can reach are facts and functions the library and the host supply.",
      "autofix": false,
      "example": {
        "before": "chart.tickStep = 0.05\nplot(close + chart.tickStep, \"Stepped\", aqua)",
        "after": "tickStep = 0.05\nplot(close + tickStep, \"Stepped\", aqua)"
      },
      "spec": "language.md 15.2, 19",
      "refines": null,
      "test": "tests/examples/rejected/OS1025.oscript"
    },
    {
      "code": "OS1026",
      "title": "Block comment",
      "severity": "error",
      "stage": "lex",
      "since": 1,
      "message": "{marker} does not open or close a comment. A comment is written // and runs to the end of its line.",
      "placeholders": {
        "marker": "the two characters that were written, the opener or the closer"
      },
      "cause": "The language has line comments and no block form (language.md 3.2). The block form is left out on purpose: an unterminated one swallows the rest of a file and reports its error at the last line, which is the worst message a compiler can produce. Without the form there is nothing special about the two characters, so a divide and a multiply are what they are and the line parses as arithmetic with its operands missing. The diagnostics then land on the operators rather than on the comment that caused them, and a reader is told three things that are each true of a program they did not write. The marker is reported where it sits instead.",
      "fix": "Write // instead, and give every line of a commented region its own //, which every editor does with one keystroke.",
      "autofix": false,
      "example": {
        "before": "lookback = 14 /* bars */",
        "after": "lookback = 14 // bars"
      },
      "spec": "language.md 3.2",
      "refines": null,
      "test": "tests/examples/rejected/OS1026.oscript"
    },
    {
      "code": "OS1027",
      "title": "Malformed colour literal",
      "severity": "error",
      "stage": "lex",
      "since": 1,
      "message": "{written} is not a colour: a colour literal is # and six or eight hexadecimal digits.",
      "placeholders": {
        "written": "the # and the run of characters written against it"
      },
      "cause": "A hexadecimal colour is # and six digits, two each for red, green and blue, or eight where the last two are the alpha byte (language.md 3.8). The three and four digit shorthands belong to other formats and this language does not have them, and a run of any other length, or one carrying a digit outside 0 to f, is a typing slip. It has a code of its own because every character in it is one the language accepts: the substitution row that gives OS1001 its sentence about # is written for a # outside a colour literal, and its advice, to delete the character or move the text into a string, would throw away a colour the writer had nearly right.",
      "fix": "Give it six hexadecimal digits, or eight where the last two are the alpha byte. A named colour or rgb(r, g, b) says the same thing without the digits.",
      "autofix": false,
      "example": {
        "before": "plot(close, \"Close\", #ff88)",
        "after": "plot(close, \"Close\", #ff8800)"
      },
      "spec": "language.md 3.8",
      "refines": "OS1001",
      "test": "tests/examples/rejected/OS1027.oscript"
    },
    {
      "code": "OS1028",
      "title": "A continuation line is not indented past its statement",
      "severity": "error",
      "stage": "lex",
      "since": 1,
      "message": "A continuation line must be indented more deeply than the line its statement began on; line {line} is indented {statement} and this line is indented {found}.",
      "placeholders": {
        "found": "the leading space count on this line",
        "statement": "the leading space count of the line the statement began on",
        "line": "the line the statement began on"
      },
      "cause": "A statement continues onto the next line when a bracket is still open, when the line ends with a binary operator, a comma, a ?, a : or an =, or when it ends with a backslash (language.md 3.11). A continuation is required to sit further right than the line the statement began on, so that a reader can tell a continued statement from a new one without scanning back up the file for a trailing operator. This is not the block rule of OS1003, and it has a code of its own for that reason: a continuation opens no block, so OS1003, whose message names the indentation every line of a block carries and whose fix offers to end that block, would state a fact about a block that is not there.",
      "fix": "Indent this line further than the {statement} spaces on line {line}. Four more is the convention and the formatter's output.",
      "autofix": true,
      "example": {
        "before": "total = ema(close, 9) +\nema(close, 21)",
        "after": "total = ema(close, 9) +\n        ema(close, 21)"
      },
      "spec": "language.md 3.11",
      "refines": "OS1003",
      "test": "tests/examples/rejected/OS1028.oscript"
    },
    {
      "code": "OS1029",
      "title": "A name written against a number",
      "severity": "error",
      "stage": "lex",
      "since": 1,
      "message": "{written} is neither a number nor a name: the number literal ends at {number}, and a name cannot begin with a digit.",
      "placeholders": {
        "written": "the whole run, the number literal and the name characters against it",
        "number": "the part of the run that is a number literal"
      },
      "cause": "A number literal is decimal, with an optional fractional part and an optional exponent, or 0x and hexadecimal digits. There is no octal form and no binary form, and an underscore belongs to a literal only where a digit follows it (language.md 3.5). A name cannot begin with a digit (language.md 3.3). A base prefix the language does not have, a unit written against a quantity, and a literal that ends in an underscore all produce this run. The whole run is reported rather than its first character, because every character in it is one the language accepts: naming the leading digit would name something legal, and deleting it, which is what OS1001 advises, leaves a valid name behind and a program that means something else.",
      "fix": "Write the value in a form the language has: a decimal literal, or 0x and hexadecimal digits. There is no binary form and no octal form, and an underscore separates digit groups only where a digit follows it. Where a number and a name were meant as two things, put an operator between them.",
      "autofix": false,
      "example": {
        "before": "mask = 0b1011",
        "after": "mask = 0x0b"
      },
      "spec": "language.md 3.3, 3.5",
      "refines": "OS1001",
      "test": "tests/examples/rejected/OS1029.oscript"
    },
    {
      "code": "OS2001",
      "title": "Name is not defined here",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} is not defined at this point in the file.",
      "placeholders": {
        "name": "the name that was read",
        "suggestion": "the closest name that is in scope here, by edit distance"
      },
      "cause": "The file is the body of the per-bar loop and runs top to bottom, so a name must be assigned above the line that reads it. A name first assigned inside a block belongs to that block and is not visible outside it. A misspelling arrives here too.",
      "fix": "Assign {name} above this line, move this line below its assignment, or correct the spelling to {suggestion}.",
      "autofix": false,
      "example": {
        "before": "plot(spread, \"Spread\", aqua)\nspread = high - low",
        "after": "spread = high - low\nplot(spread, \"Spread\", aqua)"
      },
      "spec": "language.md 12.2, 12.5",
      "refines": null,
      "test": "tests/unit/check-names.test.ts"
    },
    {
      "code": "OS2002",
      "title": "The name already exists in an enclosing scope",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} is already declared at line {line}, so a second one cannot be declared here.",
      "placeholders": {
        "name": "the name being declared",
        "line": "the line of the existing declaration, or the word built-in when it is a library name"
      },
      "cause": "There is no shadowing. An assignment to a name that exists in an enclosing scope updates that name, so declaring the same name inside is a request the language has no syntax for and is always a mistake. Built-in names such as close, ema, aqua and plot live in the global scope, so assigning to one lands here as well.",
      "fix": "Rename this one, or drop the inner declaration and let the assignment update the {name} at line {line}.",
      "autofix": false,
      "example": {
        "before": "len = 20\n\nfn smooth(src) =>\n    len = 9\n    sma(src, len)",
        "after": "len = 20\n\nfn smooth(src) =>\n    inner = 9\n    sma(src, inner)"
      },
      "spec": "language.md 12.3, 12.4",
      "refines": null,
      "test": "tests/unit/check-names.test.ts"
    },
    {
      "code": "OS2003",
      "title": "Types do not match",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{leftType} and {rightType} do not mix here.",
      "placeholders": {
        "leftType": "the type of the left operand or of the name's first assignment, or the words a per-bar value where the position takes a value of any type and a declaration handle was written",
        "rightType": "the type of the right operand or of the value being assigned"
      },
      "cause": "There is no implicit conversion anywhere in the language: 0 is not false, an empty string is not false, and a number is not a string. A name's type is fixed by its first assignment, so assigning a different type later arrives here too. A first assignment of none fixes no type, because none is a member of every type; the type comes from the first assignment that gives a definite one, and this code names the second definite type rather than the first. Every silent coercion rule is a source of bugs that survive review, and a trading script that quietly treats a zero as a false is a bug nobody finds until it costs money. A declaration handle arrives here as well: plot(), plotCandles(), fill() and level() return the compile-time half of a declaration (language.md 5.4), so a handle in a position that requires a value has nothing to give, and the message names its type as plot, fill or level.",
      "fix": "Convert explicitly: text(x) for a string, or text(x, decimals) to fix the decimals. Where no conversion applies, write the value in the type the line needs, or give the second value a name of its own. A plot, fill or level handle converts to nothing: leave it named at the top level, pass it to fill(), and use draw.line() or draw.box() where the script needs something it can keep.",
      "autofix": false,
      "example": {
        "before": "s = \"count: \" + 5",
        "after": "s = \"count: \" + text(5)"
      },
      "spec": "language.md 5.3, 5.4, 10.1",
      "refines": null,
      "test": "tests/unit/check-handles.test.ts"
    },
    {
      "code": "OS2004",
      "title": "This value has no history",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{expr} has no history, so [] cannot read a past value of it.",
      "placeholders": {
        "expr": "the expression the history operator was applied to"
      },
      "cause": "History is retained for four kinds of value: a built-in series, a name assigned at the top level of the file, a call to a function declared to return a series, and a series parameter of a user function. Retaining it for every temporary inside every block would cost memory per bar and would not run fifty thousand bars in a browser tab. A name bound to a declaration handle is none of the four, although it sits at the top level: it is a compile-time binding with no per-bar value at all. A runtime object carries no history either, so [] on a line, a label, a box, a polyline or a table is this error as well (language.md 5.4).",
      "fix": "If the value is a per-bar number computed inside a block or left as a temporary, assign it at the top level of the file and read the history of that top level name. If it is a declaration handle, a runtime object or a library fact that is not a series, no name gives it a history: assign what you want to look back at to a top level name of its own, and read that.",
      "autofix": false,
      "example": {
        "before": "if trending\n    body = close - open\n    plot(body[1], \"Previous body\", aqua)",
        "after": "body = close - open\nplot(trending ? body[1] : none, \"Previous body\", aqua)"
      },
      "spec": "language.md 5.2, 5.4",
      "refines": null,
      "test": "tests/unit/check-types.test.ts"
    },
    {
      "code": "OS2005",
      "title": "Recursive call",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} calls itself: {cycle}.",
      "placeholders": {
        "name": "the function at the start of the cycle",
        "cycle": "the call chain, from the function back to itself"
      },
      "cause": "State slots for var and for stateful library calls are allocated statically, one per call site. Recursion would need a dynamic stack of them, whose cost would be paid on every bar of every script to support a form a per-bar language almost never needs.",
      "fix": "Rewrite it as a loop, or split the work into two functions that do not call each other.",
      "autofix": false,
      "example": {
        "before": "fn total(n) =>\n    if n <= 0\n        return 0\n    close[n] + total(n - 1)",
        "after": "fn total(n) =>\n    runningTotal = 0.0\n    for i = 0 to n\n        runningTotal += close[i]\n    runningTotal"
      },
      "spec": "language.md 11.4",
      "refines": null,
      "test": "tests/unit/check-names.test.ts"
    },
    {
      "code": "OS2006",
      "title": "Assignment to a loop variable",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} is this loop's variable and cannot be assigned inside the body.",
      "placeholders": {
        "name": "the loop variable"
      },
      "cause": "The loop controls its own variable, so a body that also writes to it produces a loop whose iteration count cannot be read from its header.",
      "fix": "Use break to leave early, or keep a separate name for the value the body changes.",
      "autofix": false,
      "example": {
        "before": "for i = 0 to 9\n    if close[i] > hi\n        i = 9",
        "after": "for i = 0 to 9\n    if close[i] > hi\n        break"
      },
      "spec": "language.md 10.3",
      "refines": null,
      "test": "tests/unit/check-names.test.ts"
    },
    {
      "code": "OS2007",
      "title": "The file has no declaration",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "A file needs one study() or strategy() declaration before any other statement.",
      "placeholders": {},
      "cause": "The declaration supplies the title, the pane, the precision and the settings the host needs before the first bar runs. Without one there is nothing to put in a legend and nothing to name in a picker.",
      "fix": "Add study(\"Name\") as the first statement, or strategy(\"Name\") if the file places orders.",
      "autofix": false,
      "example": {
        "before": "fast = ema(close, 9)\nplot(fast, \"Fast\", aqua)",
        "after": "study(\"EMA\", overlay = true)\n\nfast = ema(close, 9)\nplot(fast, \"Fast\", aqua)"
      },
      "spec": "language.md 13.1",
      "refines": null,
      "test": "tests/unit/check-support.ts"
    },
    {
      "code": "OS2008",
      "title": "More than one declaration",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "This file already declares {kind} at line {line}.",
      "placeholders": {
        "kind": "study or strategy, whichever came first",
        "line": "the line of the first declaration"
      },
      "cause": "Two declarations would need a rule for whose overlay, precision and title win, and the answer to that question is always that there should have been one. A strategy accepts every study option, so a file that wants both is a strategy.",
      "fix": "Delete this declaration and move the options you wanted onto the one at line {line}.",
      "autofix": false,
      "example": {
        "before": "study(\"EMA cross\", overlay = true)\nstrategy(\"EMA cross\")",
        "after": "strategy(\"EMA cross\", overlay = true)"
      },
      "spec": "language.md 13.1",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS2009",
      "title": "Unknown member of a namespace",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{namespace} has no member named {member}.",
      "placeholders": {
        "namespace": "the namespace that was read",
        "member": "the member name that does not exist",
        "suggestion": "the closest member of that namespace, by edit distance"
      },
      "cause": "Namespaces hold a fixed set of names, published in the library manifest the editor completes from. A member that does not exist is a typo or a name from a different namespace.",
      "fix": "Use one of {namespace}'s members; {suggestion} is the closest match to what was written.",
      "autofix": false,
      "example": {
        "before": "plot(bar.idx, \"Bar\", aqua)",
        "after": "plot(bar.index, \"Bar\", aqua)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/unit/check-names.test.ts"
    },
    {
      "code": "OS2010",
      "title": "This name is not a function",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} is {type}, not a function, so it cannot be called.",
      "placeholders": {
        "name": "the name that was called",
        "type": "the type the name holds",
        "suggestion": "the library function whose name is closest, with its first argument filled in"
      },
      "cause": "A built-in series and a user value are read bare. An argument list after one of them is usually a library function that was remembered with the wrong name.",
      "fix": "Remove the argument list to read the value, or call the function that was meant: {suggestion}.",
      "autofix": false,
      "example": {
        "before": "v = volume(20)",
        "after": "v = sma(volume, 20)"
      },
      "spec": "language.md 15.1",
      "refines": null,
      "test": "tests/unit/check-names.test.ts"
    },
    {
      "code": "OS2011",
      "title": "A condition must be a bool",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "This condition is {type}; a condition must be bool or none.",
      "placeholders": {
        "type": "the type the condition expression produced",
        "name": "the condition expression as written, or its name when it is one"
      },
      "cause": "There is no truthiness. A number is not a condition, a string is not a condition, and an absent value takes the false branch only after the condition has been written as a genuine test.",
      "fix": "Write the test out: {name} > 0 for a count, isNone({name}) for absence, {name} != \"\" for a string.",
      "autofix": false,
      "example": {
        "before": "if hitCount\n    signal(\"SEEN\")",
        "after": "if hitCount > 0\n    signal(\"SEEN\")"
      },
      "spec": "language.md 5.3, 10.2",
      "refines": "OS2003",
      "test": "tests/unit/check-types.test.ts"
    },
    {
      "code": "OS2012",
      "title": "The two arms of the ternary have different types",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "The arms of this ? : are {leftType} and {rightType}.",
      "placeholders": {
        "leftType": "the type of the arm before the colon",
        "rightType": "the type of the arm after the colon"
      },
      "cause": "The ternary yields one value, so both arms must agree on its type. The one exception is none, which is a member of every type and is how an arm says there is nothing here.",
      "fix": "Make both arms the same type with text() or toNumber(), or use none for the empty arm.",
      "autofix": false,
      "example": {
        "before": "label = up ? 1 : \"down\"",
        "after": "label = up ? \"up\" : \"down\""
      },
      "spec": "language.md 9.5",
      "refines": "OS2003",
      "test": "tests/unit/check-types.test.ts"
    },
    {
      "code": "OS2013",
      "title": "An array literal mixes types",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "This array holds {firstType} at index 0 and {otherType} at index {index}.",
      "placeholders": {
        "firstType": "the type of the first element",
        "otherType": "the type of the element that disagrees",
        "index": "the index of the element that disagrees"
      },
      "cause": "An array is homogeneous, which is what lets size, sum, avg and sort mean one thing. A mixed literal is usually two lists that belong side by side.",
      "fix": "Make every element {firstType}, or keep two arrays and index them together.",
      "autofix": false,
      "example": {
        "before": "rows = [\"RSI\", 14, \"EMA\", 9]",
        "after": "names = [\"RSI\", \"EMA\"]\nlengths = [14, 9]"
      },
      "spec": "language.md 14.1",
      "refines": "OS2003",
      "test": "tests/unit/check-types.test.ts"
    },
    {
      "code": "OS2014",
      "title": "A function cannot be used as a value",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} is a function, and version 1 has no function values.",
      "placeholders": {
        "name": "the function name that was used bare"
      },
      "cause": "Functions are not values in version 1: they cannot be assigned, stored in an array or passed as an argument. The feature is reserved rather than absent, and language.md 18 names it.",
      "fix": "Call {name} with its arguments and use the value it returns.",
      "autofix": false,
      "example": {
        "before": "src = ema\nplot(src, \"EMA\", aqua)",
        "after": "src = ema(close, 9)\nplot(src, \"EMA\", aqua)"
      },
      "spec": "language.md 11.1, 18",
      "refines": null,
      "test": "tests/emit/worked-example.test.ts"
    },
    {
      "code": "OS2015",
      "title": "The element type of this empty array is unknown",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "An empty array literal needs its element type from an annotation or from a first use.",
      "placeholders": {},
      "cause": "An array is homogeneous, so its element type has to be known before anything is pushed into it. An empty literal takes that type from an annotation when it has one, and otherwise from the first call in the file, in source order, that puts an element into it: push, unshift, insert or set. With neither an annotation nor such a call, nothing in the file says what the array holds and the language does not guess.",
      "fix": "Annotate the declaration, var hits: array<number> = [], or put the first element in with push(), unshift(), insert() or set() and let the type be read from that call.",
      "autofix": false,
      "example": {
        "before": "var hits = []\nplot(size(hits), \"Hits\", aqua)",
        "after": "var hits: array<number> = []\nplot(size(hits), \"Hits\", aqua)"
      },
      "spec": "language.md 14.1",
      "refines": null,
      "test": "tests/unit/check-types.test.ts"
    },
    {
      "code": "OS2016",
      "title": "Unknown type in an annotation",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{type} is not a type.",
      "placeholders": {
        "type": "the word that was written where a type was expected"
      },
      "cause": "The types are number, string, bool, color, none, array<T> and the five runtime object types line, label, box, polyline and table, with series in front where a per-bar value is meant. There is no integer type: a length, a bar count and a price are all number. The declaration handle types plot, fill and level are deliberately not in the grammar, so writing one in an annotation is this error as well: a handle can never be a var, a parameter, a return value or an array element, and there is nothing left for an annotation to describe.",
      "fix": "Use number, string, bool, color, array<T>, or an object type (line, label, box, polyline, table), with series in front for a per-bar value.",
      "autofix": false,
      "example": {
        "before": "fn band(src: series number, len: int = 20) =>\n    sma(src, len)",
        "after": "fn band(src: series number, len: number = 20) =>\n    sma(src, len)"
      },
      "spec": "language.md 5.1, 5.4, 19",
      "refines": null,
      "test": "tests/unit/check-types.test.ts"
    },
    {
      "code": "OS2017",
      "title": "A function with this name is already declared",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} is already declared as a function at line {line}.",
      "placeholders": {
        "name": "the function name",
        "line": "the line of the first declaration"
      },
      "cause": "A user function is not overloaded in version 1, so one name in a file is one function. Two declarations would make the call site's meaning depend on argument types, which is exactly the kind of resolution a reader cannot do in their head. The library's own overloads are a different thing: they are a fixed published set, round() and clear() among them, and a script cannot add to it.",
      "fix": "Rename one of them, or give the one function a default argument that covers both uses.",
      "autofix": false,
      "example": {
        "before": "fn band(src) => sma(src, 20)\nfn band(src, len) => sma(src, len)",
        "after": "fn band(src, len = 20) => sma(src, len)"
      },
      "spec": "language.md 11.1",
      "refines": null,
      "test": "tests/unit/check-names.test.ts"
    },
    {
      "code": "OS2018",
      "title": "Duplicate parameter name",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} appears twice in this parameter list.",
      "placeholders": {
        "name": "the repeated parameter name"
      },
      "cause": "Two parameters with one name make every use of that name inside the body ambiguous, and a named argument at the call site could not say which one it meant.",
      "fix": "Rename the second parameter, so every name in the list appears once.",
      "autofix": false,
      "example": {
        "before": "fn ratio(src, src) => src / src[1]",
        "after": "fn ratio(src, len) => src / src[len]"
      },
      "spec": "language.md 11.2",
      "refines": null,
      "test": "tests/unit/check-names.test.ts"
    },
    {
      "code": "OS2019",
      "title": "This type cannot be an array element",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "array<{type}> is not a type: {type} cannot be an array element.",
      "placeholders": {
        "type": "the element type written inside the angle brackets"
      },
      "cause": "An array element is a number, a string, a bool, a color, or one of the runtime object types of language.md 5.4, and nothing else. A declaration handle is the compile-time half of a declaration and has no run-time value, so there would be nothing to store. A series is a per-bar history, and an array of them would be a second history the engine retained per element, as many as the script chose to push. An array of arrays is the matrix that language.md 14.2 reserves for a later version.",
      "fix": "Use an element type an array holds: number, string, bool, color, line, label, box, polyline or table. A plot cannot be kept anywhere, so declare each plot at the top level and give it its own name.",
      "autofix": false,
      "example": {
        "before": "var edges: array<plot> = []\npush(edges, plot(upper, \"Upper\", aqua))",
        "after": "upperEdge = plot(upper, \"Upper\", aqua)\nlowerEdge = plot(lower, \"Lower\", aqua)\nfill(upperEdge, lowerEdge, color = fade(aqua, 88))"
      },
      "spec": "language.md 5.4, 14.1, 19",
      "refines": "OS2016",
      "test": "tests/unit/check-types.test.ts"
    },
    {
      "code": "OS2020",
      "title": "Name is planned, not implemented",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} is planned and is not implemented in this version.",
      "placeholders": {
        "name": "the planned name that was called or read"
      },
      "cause": "The library names a few calls and facts it does not implement yet, so that the gap is visible rather than left for a reader to guess at (stdlib.md 1). The checker knows this name and knows it carries no behaviour, which is a different fact from a name it has never heard of: nothing about the spelling is wrong, no line above it would help, and the name starts working on a version that implements it.",
      "fix": "Compute what {name} would give from names the library implements today, or take the line out until a version implements it. Do not reach for the nearest name that compiles: a neighbour computes something else, and a plot that quietly changes meaning is worse than one that refuses to compile.",
      "autofix": false,
      "example": {
        "before": "zScore = (close - sma(close, 20)) / stdev(close, 20)\nplot(math.tanh(zScore), \"Squashed\", aqua)",
        "after": "zScore = (close - sma(close, 20)) / stdev(close, 20)\ndoubled = exp(2 * zScore)\nplot((doubled - 1) / (doubled + 1), \"Squashed\", aqua)"
      },
      "spec": "stdlib.md 1",
      "refines": "OS2001",
      "test": "tests/unit/check-names.test.ts"
    },
    {
      "code": "OS3001",
      "title": "Wrong number of arguments",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} takes {expected} arguments and {found} were given.",
      "placeholders": {
        "name": "the function being called",
        "expected": "the number of parameters, or the range when some have defaults",
        "found": "the number of arguments at this call site",
        "signature": "the function's full signature, parameter names and defaults included"
      },
      "cause": "A call site is checked against the declared parameter list. Parameters with defaults may be left out, and every parameter without one must be supplied.",
      "fix": "Pass the arguments the signature names: {signature}.",
      "autofix": false,
      "example": {
        "before": "e = ema(close, 9, 2)",
        "after": "e = ema(close, 9)"
      },
      "spec": "language.md 11.2",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3002",
      "title": "Unknown named argument",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} has no argument called {argument}.",
      "placeholders": {
        "name": "the function being called",
        "argument": "the named argument that does not exist",
        "names": "every argument name the function accepts, in declaration order",
        "suggestion": "the closest accepted name, by edit distance"
      },
      "cause": "Named arguments are matched against the parameter list by exact name. A name that is not on the list is a spelling that the call site and the function disagree about, and ignoring it would leave the argument silently unapplied.",
      "fix": "Use one of {names}; {suggestion} is the closest to what was written.",
      "autofix": false,
      "example": {
        "before": "plot(v, \"V\", colour = aqua)",
        "after": "plot(v, \"V\", color = aqua)"
      },
      "spec": "language.md 11.2",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3003",
      "title": "This option must be a constant",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{option} is read once, before the first bar, so it cannot depend on bar data.",
      "placeholders": {
        "option": "the option that was given a bar-dependent value"
      },
      "cause": "The declaration builds the legend, the axis and the settings dialog before bar 0 runs, so its options must be literals, arithmetic over literals, or an input() written as the whole of the value; an expression over an input is OS3025. A value that changes per bar has no single answer at the moment the dialog is built. The rule covers more than the declaration's own options: every argument that lands in a declaration fixed before bar 0 arrives here too, signal's at, shape and color, table's position, rows and cols, and a plot's style arguments among them. An input() counts as a constant for this purpose, because the engine resolves inputs at load and substitutes the resolved value before bar 0 runs.",
      "fix": "Use a literal, or make it tunable with an input(): {option} = input(2, \"{option}\").",
      "autofix": false,
      "example": {
        "before": "study(\"Range\", precision = round(close / 1000))",
        "after": "study(\"Range\", precision = input(2, \"precision\"))"
      },
      "spec": "language.md 13.2, 15.3",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3004",
      "title": "Argument is not a valid whole number",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name}'s {argument} must be a whole number {range}; {found} was given.",
      "placeholders": {
        "name": "the function being called",
        "argument": "the parameter name",
        "range": "the accepted range, such as 1 or more",
        "found": "the literal value that was written"
      },
      "cause": "A lookback length, an index and a loop step are counts of bars or of elements. A fractional value is rejected rather than truncated, because a length of 14.5 is a bug in the script and rounding it hides the bug. A step of 0 is rejected because it is the one loop that cannot finish.",
      "fix": "Pass a whole number inside {range}, and wrap a computed value in floor() or round().",
      "autofix": false,
      "example": {
        "before": "t = table(\"Summary\", 2.5, 2)",
        "after": "t = table(\"Summary\", 3, 2)"
      },
      "spec": "language.md 5.1, 10.3",
      "refines": null,
      "test": "tests/engine/machine.test.ts"
    },
    {
      "code": "OS3005",
      "title": "Positional argument after a named one",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "A positional argument cannot follow a named one.",
      "placeholders": {},
      "cause": "Once an argument is named, the position of the arguments after it no longer says which parameter they fill. The order is positional first, named afterwards, which keeps every call site readable without the signature in front of you.",
      "fix": "Name this argument too, or move it in front of the first named argument.",
      "autofix": false,
      "example": {
        "before": "b = band(close, len = 20, 3)",
        "after": "b = band(close, len = 20, mult = 3)"
      },
      "spec": "language.md 11.2",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3006",
      "title": "This call must be at the top level",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} defines part of the study's fixed shape and cannot appear inside {construct}.",
      "placeholders": {
        "name": "the call, one of plot, plotCandles, fill, level, table, leg.fixed or leg.relative",
        "construct": "the enclosing construct, such as an if block, a loop or a function body"
      },
      "cause": "The set of plotted columns, bands, levels and grids is fixed before bar 0 so the chart can build a legend, an axis and a settings dialog. A call inside a branch would add a column on some bars and not others, and there would be nothing stable to name. table() is on the list for the same reason, the grid's size and corner being part of the study's fixed shape, although what it returns is a runtime object that cell() writes to per bar (language.md 5.4). A leg declaration is on the list for the same reason: the set of contracts a strategy trades is fixed before bar 0, and a leg that existed on some bars and not others would leave the run's record with nothing to key on. A drawing or an alert call inside a request expression is the same error for a related reason: that expression is evaluated on another instrument's bars, so there is no bar of this chart for it to draw on.",
      "fix": "Move the call to the top level and hide it per bar by passing none: plot(cond ? value : none, ...). Inside a request expression, read the value first and draw with it afterwards. A leg is not hidden by passing none: declare it at the top level and decide per bar whether to send it an order.",
      "autofix": false,
      "example": {
        "before": "if trending\n    plot(ema20, \"EMA 20\", aqua)",
        "after": "plot(trending ? ema20 : none, \"EMA 20\", aqua)"
      },
      "spec": "language.md 7.1, 15.3; stdlib.md 17.6",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3007",
      "title": "input() must be at the top level",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "input() builds one row of the settings dialog, which is read once before the first bar.",
      "placeholders": {},
      "cause": "The dialog exists before any bar runs, so every input has to be reachable without executing the script. An input inside a block would appear or vanish depending on the data, and a saved setting would have nothing to attach to.",
      "fix": "Move the input() to the top level and use the name it assigns inside the block.",
      "autofix": false,
      "example": {
        "before": "if useBand\n    len = input(20, \"Length\")",
        "after": "len = input(20, \"Length\")\nb = sma(close, len)\nplot(useBand ? b : none, \"Band\", aqua)"
      },
      "spec": "language.md 13.4",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3008",
      "title": "The value is not valid for this parameter",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{argument} accepts {values}; {found} is not one of them.",
      "placeholders": {
        "argument": "the parameter, option or setting key",
        "values": "the accepted values or the accepted form, written out",
        "found": "the value that was written or that the host supplied",
        "suggestion": "the accepted value closest to what was written"
      },
      "cause": "Some parameters take a value out of a fixed set, or in a fixed written form, rather than free text, because each one selects a different rule in the engine or the report. Two cases arrive here: a name that is not in the set, and a structured string that does not parse, a session window for instance. An unknown name has no rule to select, and defaulting quietly would change what the script does without saying so. The same failure in a setting the host supplied is OS6019, because there the value came from outside the source.",
      "fix": "Use one of {values}; {suggestion} is the closest to what was written.",
      "autofix": false,
      "example": {
        "before": "strategy(\"Breakout\", qtyType = \"shares\")",
        "after": "strategy(\"Breakout\", qtyType = \"units\")"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3009",
      "title": "This option needs another option to be set",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{option} = {value} requires {required}.",
      "placeholders": {
        "option": "the option that was set",
        "value": "the value it was set to",
        "required": "the option and value it depends on"
      },
      "cause": "A few options only mean something in combination. An alert that fires on every execution of a bar only has executions to fire on in a file that acts on unconfirmed bars. Accepting the option on its own would leave it doing nothing, silently, which is the worst of the three possible behaviours.",
      "fix": "Set {required} in the declaration, or choose a value of {option} that stands on its own.",
      "autofix": false,
      "example": {
        "before": "study(\"Ticks\")\n\nif close > open\n    alert(\"Up\", id = \"up\", frequency = \"everyUpdate\")",
        "after": "study(\"Ticks\", onUnconfirmed = true)\n\nif close > open\n    alert(\"Up\", id = \"up\", frequency = \"everyUpdate\")"
      },
      "spec": "language.md 7.5, 13.2",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3010",
      "title": "Two arguments that cannot both be given",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{first} and {second} set the same thing two ways.",
      "placeholders": {
        "first": "the first of the two arguments",
        "second": "the second of the two arguments"
      },
      "cause": "Two arguments that set one thing have to be reconciled, and every rule for reconciling them surprises somebody, so the call is refused and the script says which it meant. There are three pairs. An exit level can be written as an absolute price or as a distance from the entry, and the candidate rules (the nearer one, the later one, the absolute one) each surprise someone. A band takes color for both of its sides, or colorUp and colorDown for the leading and the lagging side, and color together with either of those leaves no answer for which side wins. The third is a relative leg described as a future and given a right or a strike offset, which are fields of an option.",
      "fix": "Keep one of the two: an absolute price or a distance from the entry, one colour for the whole band or a colour for each side, and on a leg described as a future neither right nor strikeOffset.",
      "autofix": false,
      "example": {
        "before": "exit(limit = 105, profit = 5)",
        "after": "exit(limit = 105)"
      },
      "spec": "language.md 13.3, 15.3",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3011",
      "title": "Argument has the wrong type",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name}'s {argument} is {expected}; {found} was given.",
      "placeholders": {
        "name": "the function being called",
        "argument": "the parameter name",
        "expected": "the declared parameter type",
        "found": "the type of the expression at the call site"
      },
      "cause": "Arguments are checked against the declared parameter types, with broadcast as the only widening: a plain value may be passed where a series is expected, and it is read as that same value on every bar. Nothing else converts on its own. A declaration handle passed to an argument that does not take one arrives here too; where that argument wanted a runtime object the case has its own code, OS3019, and fill's two plot arguments have OS3020.",
      "fix": "Convert the value with text(), toNumber() or toBool(), or pass an expression of type {expected}.",
      "autofix": false,
      "example": {
        "before": "e = ema(close, \"9\")",
        "after": "e = ema(close, 9)"
      },
      "spec": "language.md 5.2, 5.3",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3012",
      "title": "A required argument is missing",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} requires {argument}, which has no default.",
      "placeholders": {
        "name": "the function being called",
        "argument": "the parameter that was left out",
        "example": "a filled-in call showing the argument in place"
      },
      "cause": "A parameter without a default has no value the engine could invent. The title of a study and the source of an indicator are the common cases, and an order's leg argument in a file that declares more than one leg is a third: with several contracts to choose from there is none the engine could pick.",
      "fix": "Pass {argument} at the call site, as the example shows: {example}.",
      "autofix": false,
      "example": {
        "before": "study(overlay = true)",
        "after": "study(\"Range breakout\", overlay = true)"
      },
      "spec": "language.md 11.2, 13.2",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3013",
      "title": "Argument given twice",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{argument} is given twice at this call site.",
      "placeholders": {
        "argument": "the parameter that received two values"
      },
      "cause": "A named argument may not repeat one already filled by position, and may not appear twice. Either would leave the reader guessing which value wins.",
      "fix": "Delete one of the two, keeping the value that was meant.",
      "autofix": false,
      "example": {
        "before": "b = band(close, 50, len = 20)",
        "after": "b = band(close, len = 20)"
      },
      "spec": "language.md 11.2",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3014",
      "title": "limits() is in the wrong place",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "limits() appears at most once, immediately after the declaration; this one is at line {line}.",
      "placeholders": {
        "line": "the line the limits() call was found on"
      },
      "cause": "The budgets apply to the whole run and are read before the first bar. One fixed position means a reader can see a script's budgets without searching the file, and two calls would need a rule for which one wins.",
      "fix": "Move the limits() line directly under study(...) or strategy(...), and merge two calls into one.",
      "autofix": false,
      "example": {
        "before": "study(\"Heavy\")\n\nlen = input(20, \"Length\")\nlimits(loops = 50_000_000)",
        "after": "study(\"Heavy\")\nlimits(loops = 50_000_000)\n\nlen = input(20, \"Length\")"
      },
      "spec": "language.md 10.7",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3015",
      "title": "limits() takes literal numbers",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "limits() is read before the first bar, so {option} must be a literal number.",
      "placeholders": {
        "option": "the limits option that was given a computed value"
      },
      "cause": "The engine allocates against these budgets before it runs anything, so there is no bar on which a computed budget could be evaluated. An input() is not accepted here either, because a budget that a settings dialog can change is a budget a reader cannot see.",
      "fix": "Write the number: limits(loops = 50_000_000).",
      "autofix": false,
      "example": {
        "before": "limits(loops = maxBars * 1000)",
        "after": "limits(loops = 50_000_000)"
      },
      "spec": "language.md 10.7",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3016",
      "title": "range must be a low and a high",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "range is [{low}, {high}]; it takes two numbers and the first must be below the second.",
      "placeholders": {
        "low": "the first element as written",
        "high": "the second element as written"
      },
      "cause": "The range option fixes the study pane's scale, so it is exactly two numbers in axis order. A reversed or single-element range has no scale to build.",
      "fix": "Write two numbers, lowest first: range = [0, 100].",
      "autofix": false,
      "example": {
        "before": "study(\"RSI\", range = [100, 0])",
        "after": "study(\"RSI\", range = [0, 100])"
      },
      "spec": "language.md 13.2",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3017",
      "title": "Two of these share a name",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{kind} names must be unique in a file; {name} is also used at line {line}.",
      "placeholders": {
        "kind": "the thing being named: plot, plotCandles, level, input, table, alert or leg",
        "name": "the repeated name, quoted",
        "line": "the line of the first use of that name"
      },
      "cause": "The legend row, the settings dialog and the saved layout all key a column by its name, and an alert message names it. Two columns with one name would overwrite each other's saved settings. fill is not on the list: a band has no name of its own and is identified by the two plots it is drawn between. A leg's name is what every later call keys on, so two legs with one name leave every leg call with no answer. An alert is named by its id, written or derived from the line, and a subscription is kept under that name, so two alerts sharing one leave the user subscribed to whichever of the two the host kept.",
      "fix": "Rename one of them so each name appears once.",
      "autofix": false,
      "example": {
        "before": "plot(fast, \"EMA\", aqua)\nplot(slow, \"EMA\", orange)",
        "after": "plot(fast, \"EMA fast\", aqua)\nplot(slow, \"EMA slow\", orange)"
      },
      "spec": "language.md 15.3",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3018",
      "title": "The default is not in the options list",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "This input's default {default} is not one of options {values}.",
      "placeholders": {
        "default": "the default value as written",
        "values": "the options list as written"
      },
      "cause": "An input with options is a dropdown, and its default is the row that is selected when the dialog opens. A default outside the list leaves the dialog with nothing selected and the script with a value the user cannot reproduce.",
      "fix": "Add {default} to options, or make the default one of the listed values.",
      "autofix": false,
      "example": {
        "before": "mode = input(\"medium\", \"Mode\", options = [\"fast\", \"slow\"])",
        "after": "mode = input(\"fast\", \"Mode\", options = [\"fast\", \"slow\"])"
      },
      "spec": "language.md 13.4",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3019",
      "title": "A declaration handle in an object argument",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name}'s {argument} is {expected}; {found} is a declaration handle, which has no value at run time.",
      "placeholders": {
        "name": "the function being called",
        "argument": "the parameter name",
        "expected": "the object type the parameter takes",
        "found": "the handle type at the call site: plot, fill or level"
      },
      "cause": "plot(), plotCandles(), fill() and level() return a declaration handle: the compile-time half of a declaration, an entry in the program's outputs, with no run-time representation at all. The draw setters, cell() and clear() take a runtime object, which is a value the script made on a bar and can keep, move and delete. The two kinds are separated in the type system for exactly this reason, and fill() is the one call in version 1 that takes a handle.",
      "fix": "Pass an object the script created with draw.line(), draw.box() or draw.label(), and change a plot's own appearance through the arguments of the plot call instead.",
      "autofix": false,
      "example": {
        "before": "upper = plot(basis + dev, \"Upper\", aqua)\ndraw.setColor(upper, red)",
        "after": "plot(basis + dev, \"Upper\", color = close > basis ? lime : red)"
      },
      "spec": "language.md 5.4, 15.3",
      "refines": "OS3011",
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3020",
      "title": "fill needs two declared plots",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "fill's {argument} is {found}; it takes a plot declared by plot() or plotCandles().",
      "placeholders": {
        "argument": "the parameter that was given the wrong thing, plotA or plotB",
        "found": "the type of the expression at the call site"
      },
      "cause": "A band is one entry of the chart contract's shaded bands, and that entry holds the two plot keys the band is drawn between (compiled-program.md 2.8). A bare expression has no key, because no column was ever declared for it, so there is nothing in the contract for it to compile into. Naming the two edges is what makes a band readable as well: it is drawn between two columns the chart already shows, rather than instead of them.",
      "fix": "Plot both edges at the top level, name each one, and pass the two names to fill().",
      "autofix": false,
      "example": {
        "before": "fill(basis + dev, basis - dev, color = fade(aqua, 88))",
        "after": "upper = plot(basis + dev, \"Upper\", aqua)\nlower = plot(basis - dev, \"Lower\", aqua)\nfill(upper, lower, color = fade(aqua, 88))"
      },
      "spec": "language.md 5.4, 15.3",
      "refines": "OS3011",
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3021",
      "title": "An input written in place has no title",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "An input() assigned to no name is named by its title, and this one has no title written as a string literal.",
      "placeholders": {},
      "cause": "A host stores one value per input key, and the key is the name the input was assigned to (host-interface.md 8.1). An input written where a value belongs is assigned to no name, so its title is its key as well as its dialog label. The title is read from the line as a string literal rather than folded, because a key and a label are both fixed before anything is computed and because the row a reader sees should be named on the line that declares it. With neither a name nor such a title there is nothing to label the row with and nothing to store a user's value under, and a key made from the input's position instead would move the moment another input was written above it, taking a user's stored value onto a different row.",
      "fix": "Give it a title written as a string literal: input(2, \"Precision\").",
      "autofix": false,
      "example": {
        "before": "study(\"Range\", precision = input(2))",
        "after": "study(\"Range\", precision = input(2, \"Precision\"))"
      },
      "spec": "language.md 13.4, host-interface.md 8.1",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3022",
      "title": "Two inputs share a settings key",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "This input is keyed by its title {name}, which is already the name of the input at line {line}.",
      "placeholders": {
        "name": "the title of the input written in place, quoted",
        "line": "the line of the input that already carries that key"
      },
      "cause": "A host stores one value per key (host-interface.md 8.1). An input assigned to a name is keyed by that name, and one written in place is keyed by its title, so a title that spells another input's name puts two rows on one key. One user value would then serve two rows and nothing anywhere decides which of them gets it. Two inputs carrying one title are OS3017 for the same reason.",
      "fix": "Give this one a title of its own, or rename the input at line {line}.",
      "autofix": false,
      "example": {
        "before": "width = input(2, \"Width\")\nplot(close + width * input(3, \"width\"), \"Band\", aqua)",
        "after": "width = input(2, \"Width\")\nplot(close + width * input(3, \"Multiplier\"), \"Band\", aqua)"
      },
      "spec": "language.md 13.4, host-interface.md 8.1",
      "refines": "OS3017",
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3023",
      "title": "An order names a leg this file does not declare",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} was given a {argument}, and this file declares none.",
      "placeholders": {
        "name": "the order function that was called",
        "argument": "the parameter that names the declaration, which is leg"
      },
      "cause": "Every order function names the leg it acts on, and a leg is a contract declared before the run (stdlib.md 17.1, 17.6). A file that declares no leg has exactly one, the instrument its chart is showing, and every order acts on it with no leg named. So in a file with no leg declaration there is no name a leg argument could carry, and one written there names nothing. Ignored, it is silent in the most expensive way an order can be: a script that entered under one name and closed another flattened the only leg there is and was told nothing, and a name the script computed was dropped just as quietly. It is refused whatever the argument holds, rather than held against a list of accepted values the way OS3008 holds every other fixed set, because here the list is empty and the value is not what is wrong.",
      "fix": "Leave {argument} out. A file that declares no leg has exactly one, and every order acts on it.",
      "autofix": false,
      "example": {
        "before": "if pos.isFlat\n    buy(qty = 1, leg = \"hedge\")\nelse\n    close()",
        "after": "if pos.isFlat\n    buy(qty = 1)\nelse\n    close()"
      },
      "spec": "stdlib.md 17.1, 17.2",
      "refines": "OS3008",
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3024",
      "title": "An input written in place has an empty title",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "An input() assigned to no name is named by its title, and this one's title is empty.",
      "placeholders": {},
      "cause": "The title of an input written where a value belongs is its settings key as well as its dialog label (host-interface.md 8.1), and the empty string is neither. There is nothing to store a user's value under and nothing to label the row with, and a second input written the same way would land on the same empty key and take the same stored value. This is the case OS3021 refuses, reached by a different edit, and it carries its own code because OS3021 tells a reader to give the input a title written as a string literal and this reader has written one. A message and a fix that are both already true of the program in front of somebody send them to change nothing. What is wrong here is not that the title was left out: it is that the title says nothing, and the fix is to give it something to say. An input assigned to a name is not this. It has a key already, and an empty title there is read as no title and labelled with the name, which language.md 13.4 states.",
      "fix": "Give the title something to say: input(2, \"Precision\").",
      "autofix": false,
      "example": {
        "before": "study(\"Range\", precision = input(2, \"\"))",
        "after": "study(\"Range\", precision = input(2, \"Precision\"))"
      },
      "spec": "language.md 13.4, host-interface.md 8.1",
      "refines": "OS3021",
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS3025",
      "title": "A setting is part of a larger expression here",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{option} is fixed before the first bar and holds an input() only as the whole of its value, so it cannot hold an expression over one.",
      "placeholders": {
        "option": "the option or field whose value reads a setting as part of something larger"
      },
      "cause": "A field fixed before bar 0 is written into the compiled program as one of two things: the value itself, which the compiler folds, or a reference to one input, which the engine resolves once at load (compiled-program.md 2.3). An expression over a setting is neither. The compiler cannot fold it, because the setting's value is not known until the host resolves the settings, and the program has no form for an expression evaluated at load, because that would be a second evaluator every engine has to agree on before the first bar. An input's own default, bounds and step are the same kind of field and are held tighter still: they are what the settings dialog shows before anybody has chosen, so none of them may read another setting at all.",
      "fix": "Declare the setting as the value itself, with an input() written as the whole of {option}, or write the value out as a literal.",
      "autofix": false,
      "example": {
        "before": "w = input(1, \"Width\")\nplot(close, \"Close\", aqua, width = w + 1)",
        "after": "w = input(2, \"Width\")\nplot(close, \"Close\", aqua, width = w)"
      },
      "spec": "language.md 13.2",
      "refines": null,
      "test": "tests/unit/check-plot-options.test.ts"
    },
    {
      "code": "OS3026",
      "title": "This option cannot be a setting",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{option} is written into the compiled program as a plain value, so a setting cannot choose it in this format version.",
      "placeholders": {
        "option": "the option that was written from an input()"
      },
      "cause": "An option fixed before bar 0 carries either its value or a reference to one input, resolved at load (compiled-program.md 2.3), and almost every option takes both. A plot's style takes only the value: its field in the compiled format is a plain string. So an input() written into it could only be folded to its default, the settings row it declares would move nothing, and a select offering values the option does not accept would pass, because the set check reads a value written out and a setting is not one. Widening the field changes the compiled format that every other engine is written against, so it is refused here rather than half carried.",
      "fix": "Write the option out as a string literal and drop the input(): style = \"step\", for instance, is one of the values OS3008 names.",
      "autofix": false,
      "example": {
        "before": "st = input(\"line\", \"Style\", options = [\"line\", \"step\", \"area\"])\nplot(close, \"Close\", aqua, style = st)",
        "after": "plot(close, \"Close\", aqua, style = \"step\")"
      },
      "spec": "language.md 13.4",
      "refines": null,
      "test": "tests/unit/check-plot-options.test.ts"
    },
    {
      "code": "OS4001",
      "title": "History index is not usable",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "[{index}] is not a whole number of bars at or above zero.",
      "placeholders": {
        "index": "the value the index expression produced on this bar"
      },
      "cause": "A history index counts bars back, so it is a whole number and it is never negative: reading the future is not available at any price. A negative literal is caught at compile time as OS3004; this is the computed case.",
      "fix": "Wrap the index in floor() or round(), and clamp a computed index with max(0, n).",
      "autofix": false,
      "example": {
        "before": "prev = close[len / 2]",
        "after": "prev = close[floor(len / 2)]"
      },
      "spec": "language.md 7.4",
      "refines": null,
      "test": "tests/engine/machine.test.ts"
    },
    {
      "code": "OS4002",
      "title": "History index is deeper than the retained depth",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "[{index}] reaches past the retained depth of {depth} bars.",
      "placeholders": {
        "index": "the index that was requested",
        "depth": "the depth the host or the script set",
        "suggested": "an adequate depth for this script, being the deepest index it uses"
      },
      "cause": "The value existed and the engine discarded it, which is a different situation from a value that never existed. Conflating the two would hide a real bug behind a plausible gap, so this is an error while a read past the start of history is simply absent.",
      "fix": "Raise the depth in one place: limits(history = {suggested}).",
      "autofix": false,
      "example": {
        "before": "study(\"Long lookback\")\nlimits(history = 50)\n\nold = close[120]",
        "after": "study(\"Long lookback\")\nlimits(history = 120)\n\nold = close[120]"
      },
      "spec": "language.md 7.4, 10.7",
      "refines": null,
      "test": "tests/engine/machine.test.ts"
    },
    {
      "code": "OS4003",
      "title": "A whole number was required here",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{name}'s {argument} was {found} on this bar; a whole number was required.",
      "placeholders": {
        "name": "the function being called",
        "argument": "the parameter name",
        "found": "the value that reached the call"
      },
      "cause": "An index, a digit count and a repeat count are whole numbers. Where the value is a literal the checker catches it as OS3004; where it is computed it arrives here, on the bar that produced it.",
      "fix": "Round the value before passing it: floor() towards zero, round() to nearest.",
      "autofix": false,
      "example": {
        "before": "s = sma(close, len / 2)",
        "after": "s = sma(close, floor(len / 2))"
      },
      "spec": "language.md 14.1",
      "refines": null,
      "test": "tests/engine/machine.test.ts"
    },
    {
      "code": "OS4004",
      "title": "Array index out of range",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "Index {index} is outside {name}, which holds {size} elements.",
      "placeholders": {
        "index": "the index that was requested",
        "name": "the array's name",
        "size": "the array's element count on this bar"
      },
      "cause": "An array has an extent the script chose, so an index outside it is a mistake rather than a missing measurement. This is deliberately the opposite of the history operator, where reading past the start of history is absence.",
      "fix": "Guard the read with size({name}), and index from size({name}) - 1 for the last element.",
      "autofix": false,
      "example": {
        "before": "last = values[10]",
        "after": "last = size(values) > 10 ? values[10] : none"
      },
      "spec": "language.md 14.1",
      "refines": null,
      "test": "tests/engine/machine.test.ts"
    },
    {
      "code": "OS4005",
      "title": "The drawing object no longer exists",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "This {kind} was deleted on bar {bar} and cannot be changed.",
      "placeholders": {
        "kind": "the object kind: line, label, box or polyline",
        "bar": "the bar index the object was deleted on"
      },
      "cause": "An object lives from the bar that created it until the bar that deletes it, and nothing else ends its life: dropping the last name that refers to one leaves it on the chart, because there is no collection of unreachable objects. This error is the other side of that rule. A name kept in a var outlives the object it was given, so a setter reaching a deleted object is a script that has lost track of its own state and will go on doing so. A table never arrives here, because a table is never deleted: clear(t) empties it and the grid lives as long as the study. OS8019 warns about the shape that leads here, at compile time.",
      "fix": "Assign none to the name on the same path as the delete, and test isNone() on it before changing the object.",
      "autofix": false,
      "example": {
        "before": "var top = none\nif isNone(top)\n    top = draw.line(time, low, time, high)\nif close < open\n    draw.delete(top)\ndraw.setTo(top, time, high)",
        "after": "var top = none\nif isNone(top)\n    top = draw.line(time, low, time, high)\nif close < open\n    draw.delete(top)\n    top = none\nif not isNone(top)\n    draw.setTo(top, time, high)"
      },
      "spec": "language.md 5.4",
      "refines": null,
      "test": "tests/engine/objects.test.ts"
    },
    {
      "code": "OS4006",
      "title": "The array is empty",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{name} cannot take an element from an empty array.",
      "placeholders": {
        "name": "the call, one of pop, shift, min, max or avg"
      },
      "cause": "Removing or summarising an element of an empty array has no answer. Returning absence would let a script drain an array without noticing, which is the bug this catches.",
      "fix": "Test size(arr) > 0 before the call.",
      "autofix": false,
      "example": {
        "before": "oldest = shift(window)",
        "after": "oldest = size(window) > 0 ? shift(window) : none"
      },
      "spec": "language.md 14.1",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. Taking an element from an empty array raises the broader OS4004, and summarising one returns absence, which is the silent drain this entry exists to refuse. Raised when the array library tells the empty case apart from an index outside a filled array, language.md 14.1."
    },
    {
      "code": "OS4007",
      "title": "Slice range is invalid",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "slice({from}, {to}) is not a range inside an array of {size} elements.",
      "placeholders": {
        "from": "the start index, inclusive",
        "to": "the end index, exclusive",
        "size": "the array's element count on this bar"
      },
      "cause": "A slice takes from inclusive and to exclusive, so a valid range satisfies 0 <= from <= to <= size. A reversed range is not read backwards, because a slice that silently reverses is a slice nobody can read.",
      "fix": "Clamp the bounds: from = max(0, from) and to = min(size(arr), to), with from at or below to.",
      "autofix": false,
      "example": {
        "before": "tail = slice(values, size(values), 0)",
        "after": "tail = slice(values, max(0, size(values) - 10), size(values))"
      },
      "spec": "language.md 14.1",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. slice takes whatever range it is given and returns a shortened or empty array, so a reversed or out of range pair produces a plausible answer instead of a refusal. Raised when the array library checks the range against the array, language.md 14.1."
    },
    {
      "code": "OS4008",
      "title": "Table cell is outside the table",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "Cell ({row}, {column}) is outside a table of {rows} rows and {columns} columns.",
      "placeholders": {
        "row": "the row index that was written to",
        "column": "the column index that was written to",
        "rows": "the table's declared row count",
        "columns": "the table's declared column count"
      },
      "cause": "A table's shape is declared once, with the study's fixed surface, so a write outside it has no cell to land in. Growing the table on demand would change the layout between bars and would make a saved layout meaningless.",
      "fix": "Declare the table with the shape the script writes: table(\"Summary\", {rows}, {columns}).",
      "autofix": false,
      "example": {
        "before": "t = table(\"Summary\", 2, 2)\ncell(t, 2, 0, \"Total\")",
        "after": "t = table(\"Summary\", 3, 2)\ncell(t, 2, 0, \"Total\")"
      },
      "spec": "language.md 15.3",
      "refines": null,
      "test": "tests/engine/tables.test.ts"
    },
    {
      "code": "OS4009",
      "title": "Colour channel is out of range",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{name}'s {argument} is {found}; channels run 0 to 255 and alpha runs 0 to 1.",
      "placeholders": {
        "name": "the colour function: rgb, rgba or fade",
        "argument": "the channel that was out of range",
        "found": "the value that reached the call"
      },
      "cause": "A colour channel outside its range has no rendering, and clamping silently would make a study whose colours are a computation look right at the edges and wrong in between.",
      "fix": "Clamp the value where it is computed: rgb(min(255, max(0, r)), g, b).",
      "autofix": false,
      "example": {
        "before": "tint = rgb(255 * strength, 0, 0)",
        "after": "tint = rgb(min(255, max(0, 255 * strength)), 0, 0)"
      },
      "spec": "language.md 3.8",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. The colour calls build a colour from whatever channels they are given, so a channel outside its range reaches the chart rather than stopping the bar. Raised when the colour library checks each channel, language.md 3.8."
    },
    {
      "code": "OS4010",
      "title": "Calendar field is out of range",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{field} is {found}; it runs {range}.",
      "placeholders": {
        "field": "the calendar field: year, month, day, hour, minute or second",
        "found": "the value that reached the call",
        "range": "the accepted range for that field"
      },
      "cause": "A date is built from fields that each have a range, and a month of 13 is a script bug rather than a date. Rolling over into the next year would turn an off-by-one into a silently wrong timestamp, which in a session test is a whole day of wrong signals.",
      "fix": "Pass a value inside {range}, carrying the overflow into the field above it as the example does.",
      "autofix": false,
      "example": {
        "before": "t = date.from(2026, month + 1, 1)",
        "after": "t = date.from(2026 + floor(month / 12), mod(month, 12) + 1, 1)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. Building a date returns absence only when a field is not a whole number, so a month past the end of the year rolls into the next one and becomes a timestamp the script never meant. Raised when the calendar library checks each field against its range, language.md 15.2."
    },
    {
      "code": "OS4011",
      "title": "String position is outside the string",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "Position {index} is outside a string of {length} characters.",
      "placeholders": {
        "index": "the position that was requested",
        "length": "the string's length in characters"
      },
      "cause": "A string position addresses an existing character, counted in Unicode code points. Returning an empty string instead would let a parsing loop run off the end and produce a plausible empty result.",
      "fix": "Guard with str.length(s), or clamp the position with min() before the call.",
      "autofix": false,
      "example": {
        "before": "c = str.substring(sym, 10, 11)",
        "after": "c = str.length(sym) > 10 ? str.substring(sym, 10, 11) : \"\""
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. Taking part of a string slices the code points it holds, so a position outside the string returns a shorter string or an empty one, which is the plausible empty result this entry refuses. Raised when the string library checks the position against the string, language.md 15.2."
    },
    {
      "code": "OS4012",
      "title": "That value is not one of the accepted names",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{argument} accepts {values}; {found} was computed on this bar.",
      "placeholders": {
        "argument": "the parameter name",
        "values": "every accepted value, quoted and comma separated",
        "found": "the value that reached the call"
      },
      "cause": "The compile-time form of this is OS3008. Where the value is computed, the check happens on the bar that produced it, because a name that selects an engine rule cannot be guessed at and cannot be defaulted without changing what the script does.",
      "fix": "Produce the value from an input() with an options list, so only accepted names can reach the call.",
      "autofix": false,
      "example": {
        "before": "sortOrder = up ? \"ascending\" : \"desc\"\nsort(values, sortOrder)",
        "after": "sortOrder = up ? \"asc\" : \"desc\"\nsort(values, sortOrder)"
      },
      "spec": "language.md 14.1",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. A computed name outside the accepted set produces absence on every bar rather than stopping, and only a name written as a literal is refused, at compile time, with OS3008. Raised when the engine checks a computed name on the bar that produced it, language.md 14.1."
    },
    {
      "code": "OS4013",
      "title": "A loop bound is absent",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "This loop's {bound} is absent on this bar.",
      "placeholders": {
        "bound": "the bound that was absent: start, limit or step"
      },
      "cause": "A counted loop needs three numbers before it can begin. Absence propagates through arithmetic and comparison, but a loop cannot propagate it: it either runs or it does not. Treating an absent bound as zero iterations would skip work the script asked for and leave a plot that looks computed, so the bar stops instead.",
      "fix": "Give the bound a value with orElse(), or guard the loop with isNone() so a warmup bar skips it deliberately.",
      "autofix": false,
      "example": {
        "before": "for i = 0 to lookback\n    total += close[i]",
        "after": "if not isNone(lookback)\n    for i = 0 to lookback\n        total += close[i]"
      },
      "spec": "language.md 10.3",
      "refines": null,
      "test": "tests/engine/machine.test.ts"
    },
    {
      "code": "OS5001",
      "title": "Loop budget exhausted",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "This bar used its {budget} loop iterations, and the loop at line {line} was still running.",
      "placeholders": {
        "budget": "the per-bar iteration budget in force",
        "line": "the line of the loop that was running when the budget ran out",
        "suggested": "a budget that would have completed this bar, rounded up"
      },
      "cause": "Every iteration of every loop counts against one per-bar budget, so a script with one nested loop is treated like a script with ten sequential ones, and the budget resets each bar so a long dataset is not itself a reason to fail. The bar stops rather than breaking out of the loop, because a loop that ran two million times and then stopped produces a plausible wrong number, which is worse than no number.",
      "fix": "Fix the exit condition, or raise the budget in one line: limits(loops = {suggested}).",
      "autofix": false,
      "example": {
        "before": "while close[i] > close[i + 1]\n    total += close[i]",
        "after": "while i < 500 and close[i] > close[i + 1]\n    total += close[i]\n    i += 1"
      },
      "spec": "language.md 10.7",
      "refines": null,
      "test": "tests/engine/budget.test.ts"
    },
    {
      "code": "OS5002",
      "title": "The array is too large",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "An array holds at most {max} elements; {name} reached {size}.",
      "placeholders": {
        "max": "the element ceiling",
        "name": "the array's name",
        "size": "the size the array reached"
      },
      "cause": "The ceiling exists so that one script cannot exhaust a browser tab's memory and take the chart with it. It is not raised by limits() in version 1, because an array that large is almost always a window that is never trimmed.",
      "fix": "Drop the oldest element as you append: if size(arr) > 500, shift(arr).",
      "autofix": false,
      "example": {
        "before": "var window = [0.0]\npush(window, close)",
        "after": "var window = [0.0]\npush(window, close)\nif size(window) > 500\n    shift(window)"
      },
      "spec": "language.md 14.1",
      "unexercised": "The ceiling is the engine's own and it is a large one, so an example that reached it would be a run long enough to fill it rather than a script anybody would read. The before block shows the window that is never trimmed, which is the shape that gets there, and not the bar it stops on.",
      "refines": null,
      "test": "tests/engine/budget.test.ts"
    },
    {
      "code": "OS5003",
      "title": "The host refused this limits() value",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "This host allows {option} up to {max}; the file asks for {found}.",
      "placeholders": {
        "option": "the limits option",
        "max": "the host's ceiling",
        "found": "the value the file asked for"
      },
      "cause": "A host that will not run a budget says so instead of quietly capping it, because a script that silently ran under a smaller budget would produce numbers its author never asked for and could not reproduce.",
      "fix": "Lower {option} to {max} or below, or run the file on a host that allows more.",
      "autofix": false,
      "example": {
        "before": "limits(loops = 500_000_000)",
        "after": "limits(loops = 50_000_000)"
      },
      "spec": "language.md 10.7; host-interface.md 10.1",
      "refines": null,
      "test": "tests/engine/verify.test.ts"
    },
    {
      "code": "OS5004",
      "title": "The program needs more state regions than the engine allows",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "This program needs {found} state regions and the engine allows {max}; {first} calls {second} on several paths.",
      "placeholders": {
        "found": "the number of state regions the compiler would allocate",
        "max": "the engine's declared region count",
        "first": "the outer function in the nesting that caused it",
        "second": "the function it calls more than once"
      },
      "cause": "State is allocated per call path, which is what lets one function body serve many independent pieces of state. The number of paths grows multiplicatively when several functions each call the next more than once. The compiler reports it rather than emitting a program no engine will load.",
      "fix": "Call the inner function once at the top level, give its result a name, and pass that name down.",
      "autofix": false,
      "example": {
        "before": "fn inner(src) => ema(src, 20)\nfn outer(src) => inner(src) - inner(src[1])\nv = outer(close) + outer(hlc3)",
        "after": "fn inner(src) => ema(src, 20)\nbase = inner(close)\nv = base - base[1]"
      },
      "spec": "compiled-program.md, state regions",
      "refines": null,
      "test": "tests/engine/verify.test.ts"
    },
    {
      "code": "OS5005",
      "title": "Nesting is too deep",
      "severity": "error",
      "stage": "parse",
      "since": 1,
      "message": "{construct} is nested {found} deep and the ceiling is {max}.",
      "placeholders": {
        "construct": "the construct that nested too deeply: an expression, a block or a call",
        "found": "the nesting depth reached",
        "max": "the nesting ceiling"
      },
      "cause": "The ceiling keeps the parser, the checker and the engine inside a bounded stack, so no input can stop a tab. It applies to source nesting at compile time and to call depth at run time, and it is far above anything a person writes by hand: generated source is the usual way to reach it.",
      "fix": "Flatten it: give the inner expression a name at the top level and use the name.",
      "autofix": false,
      "example": {
        "before": "z = a ? b ? c ? d ? 1 : 2 : 3 : 4 : 5",
        "after": "inner = c ? (d ? 1 : 2) : 3\nz = a ? (b ? inner : 4) : 5"
      },
      "spec": "language.md 19",
      "unexercised": "The ceiling is far above anything written by hand, which is the whole point of it: generated source is how a file reaches it. The before block shows the shape at four levels, where a reader can see it, and nothing that short can raise the code.",
      "refines": null,
      "test": "tests/unit/parse-diagnostics.test.ts"
    },
    {
      "code": "OS5006",
      "title": "Too many outstanding data requests",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "This file makes {found} data requests and the host allows {max}.",
      "placeholders": {
        "found": "the number of distinct requests in the file",
        "max": "the host's ceiling on concurrent requests"
      },
      "cause": "Each higher timeframe or other-instrument read is a separate series the host fetches and keeps in step with the chart. The ceiling is the host's, and it is reported rather than silently dropping the requests past it, because a dropped request is a plot that quietly turns absent.",
      "fix": "Keep one request per symbol and timeframe, reuse the name it assigns, and delete the requests whose results are unused.",
      "autofix": false,
      "example": {
        "before": "dayHigh = req.timeframe(\"1D\", high)\nprevHigh = req.timeframe(\"1D\", high)[1]\nweekHigh = req.timeframe(\"1W\", high)",
        "after": "dayHigh = req.timeframe(\"1D\", high)\nprevHigh = dayHigh[1]\nweekHigh = req.timeframe(\"1W\", high)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/engine/requests-load.test.ts"
    },
    {
      "code": "OS5007",
      "title": "The bar took too long",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "Bar {bar} ran for {ms} ms and the host allows {max} ms.",
      "placeholders": {
        "bar": "the bar index that exceeded the budget",
        "ms": "the time the bar took",
        "max": "the host's per-bar time budget"
      },
      "cause": "A server running many strategies gives each bar a wall-clock budget, so one script cannot starve the rest. Work that does not change from bar to bar is the usual cause: recomputing over the whole history on every bar turns a linear study into a quadratic one.",
      "fix": "Keep a running value in a var and update it per bar instead of recomputing over the whole history.",
      "autofix": false,
      "example": {
        "before": "total = 0.0\nfor i = 0 to bar.index\n    total += close[i]",
        "after": "var total = 0.0\ntotal += close"
      },
      "spec": "language.md 7.1",
      "refines": null,
      "test": "tests/engine/budget.test.ts"
    },
    {
      "code": "OS5008",
      "title": "The string is too long",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "A string holds at most {max} characters; this one reached {found}.",
      "placeholders": {
        "max": "the character ceiling",
        "found": "the length that was reached"
      },
      "cause": "The ceiling catches the one shape that grows without bound by accident: text appended to a persistent string on every bar, which is a log that nothing ever trims.",
      "fix": "Keep the pieces in an array, trim it to the rows you display, and join only those.",
      "autofix": false,
      "example": {
        "before": "var logLines = \"\"\nlogLines += text(close) + \"\\n\"",
        "after": "var logLines: array<string> = []\npush(logLines, text(close))\nif size(logLines) > 50\n    shift(logLines)"
      },
      "spec": "language.md 5.1",
      "unexercised": "The ceiling is the engine's own and a bar appends a few characters, so reaching it takes a run of thousands of bars rather than an example. The before block shows the log that is never trimmed, which is the shape that gets there.",
      "refines": null,
      "test": "tests/engine/budget.test.ts"
    },
    {
      "code": "OS5009",
      "title": "The program is too large",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "This file compiles to {found} instructions and the ceiling is {max}.",
      "placeholders": {
        "found": "the instruction count the compiler produced",
        "max": "the instruction ceiling"
      },
      "cause": "The compiled program is held in memory per chart and per running strategy, so it has a size the host is willing to hold. A file at this size is nearly always repeated blocks that a function would collapse.",
      "fix": "Move the repeated block into a fn and call it, and delete branches the script no longer uses.",
      "autofix": false,
      "example": {
        "before": "a1 = sma(close, 10)\na2 = sma(close, 20)\na3 = sma(close, 30)",
        "after": "fn avgOf(len) => sma(close, len)\na1 = avgOf(10)\na2 = avgOf(20)\na3 = avgOf(30)"
      },
      "spec": "language.md 10.7",
      "refines": null,
      "test": "tests/engine/verify.test.ts"
    },
    {
      "code": "OS5010",
      "title": "Too many drawing objects",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "A script holds at most {max} drawing objects; this one would be number {found}.",
      "placeholders": {
        "max": "the number of drawing objects the host will hold at once",
        "found": "the count the object being created would have reached"
      },
      "cause": "An object lives until the script deletes it, so a script that creates one on every bar and deletes none grows for as long as the chart is open, and nothing can reclaim it: an undeleted object is held by the chart whether or not the script still names it. The ceiling is the host's, and reaching it stops the bar and names the number. The oldest object is never dropped to make room, because a study that is correct on the right of the chart and quietly wrong on the left is worse than one that stops.",
      "fix": "Delete each object when it stops being wanted, and bound the set: keep the objects in an array, and when it is longer than you want, delete the oldest object and remove the element.",
      "autofix": false,
      "example": {
        "before": "var zones: array<box> = []\npush(zones, draw.box(time, low, time, high))",
        "after": "var zones: array<box> = []\npush(zones, draw.box(time, low, time, high))\nif size(zones) > 50\n    draw.delete(element(zones, 0))\n    shift(zones)"
      },
      "spec": "stdlib.md 14.4",
      "unexercised": "The ceiling is the host's and a bar creates one object, so reaching it takes a run of thousands of bars rather than an example. The before block shows the script that creates on every bar and deletes on none, which is the shape that gets there.",
      "refines": null,
      "test": "tests/engine/objects.test.ts"
    },
    {
      "code": "OS6001",
      "title": "Unknown timeframe",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{value} is not a timeframe.",
      "placeholders": {
        "value": "the string that was passed as a timeframe"
      },
      "cause": "A timeframe is a count and a unit, written as a string: m for minutes, h for hours, D for days, W for weeks and M for months. The unit letters are case sensitive, so \"1M\" is one month and \"1m\" is one minute. A bare number is read as minutes, because that is the form an interval input supplies, so \"60\" and \"1h\" are the same timeframe.",
      "fix": "Write a count and a unit, or a bare number of minutes: \"5m\", \"1h\", \"1D\", \"1W\", \"60\".",
      "autofix": false,
      "example": {
        "before": "d = req.timeframe(\"hourly\", high)",
        "after": "d = req.timeframe(\"1h\", high)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/unit/check-repaint.test.ts"
    },
    {
      "code": "OS6002",
      "title": "The requested timeframe is lower than the chart's",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The chart is {chart} and the request asks for {requested}.",
      "placeholders": {
        "chart": "the chart's interval",
        "requested": "the interval that was requested"
      },
      "cause": "Folding a lower timeframe into a higher bar needs data from inside the bar, which the chart was not given. Inventing it is the definition of a repainting study, so the request is refused rather than approximated.",
      "fix": "Request {chart} or higher, or change the chart's interval to the lower one and fold upwards instead.",
      "autofix": false,
      "example": {
        "before": "m5 = req.timeframe(\"5\", close)",
        "after": "h1 = req.timeframe(\"60\", close)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/engine/requests-load.test.ts"
    },
    {
      "code": "OS6003",
      "title": "A per-bar name inside a request expression",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} is computed on this chart's bars, so it has no meaning on the requested ones.",
      "placeholders": {
        "name": "the file-scope name that was read inside the expression"
      },
      "cause": "The expression passed to a request is evaluated on the requested instrument's bars, in its own time. A name from this file may be read there only when it is a compile-time constant: a literal, arithmetic over literals, or an input(). A value computed on this chart's bars has no counterpart on the requested ones, and there is no honest answer for what it would mean there.",
      "fix": "Move the calculation inside the request expression, or pass a constant: a literal or an input().",
      "autofix": false,
      "example": {
        "before": "m = sma(close, 20)\nd = req.timeframe(\"1D\", close > m)",
        "after": "d = req.timeframe(\"1D\", close > sma(close, 20))"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/unit/check-repaint.test.ts"
    },
    {
      "code": "OS6004",
      "title": "The library manifest disagrees with the program",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "Entry {index} of the program names {name} with {arity} arguments; this engine's manifest has {manifest}.",
      "placeholders": {
        "index": "the entry's index in the program's function table",
        "name": "the function name the program carries",
        "arity": "the argument count the program carries",
        "manifest": "what the engine's manifest says about that name"
      },
      "cause": "A compiled program carries its own function table, and the engine checks every entry against its manifest at load: the name must exist, the argument count must match, and the state and effect facts must agree. The entries carry facts the engine already knows precisely so that they can be disagreed with, which catches a program compiled against a different library before it computes a single wrong number.",
      "fix": "Recompile the script against this engine's library, or run the program on an engine with the library version it was compiled against.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "program: library 5, entry 12 name \"stdev\" arity 3\nengine:  library 4, entry \"stdev\" arity 2",
        "after": "program: library 4, entry 12 name \"stdev\" arity 2\nengine:  library 4, entry \"stdev\" arity 2"
      },
      "spec": "compiled-program.md, the function table",
      "refines": null,
      "test": "tests/engine/verify.test.ts"
    },
    {
      "code": "OS6005",
      "title": "Unknown timezone",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "{value} is not a timezone this host knows.",
      "placeholders": {
        "value": "the timezone name that was given"
      },
      "cause": "Timezone names come from the host's timezone database, and an abbreviation is not one of them: several abbreviations mean two different offsets in different parts of the world, which is the kind of ambiguity a session test cannot carry.",
      "fix": "Use a full area and location name from the host's list, or leave the argument out to use the chart's own timezone.",
      "autofix": false,
      "example": {
        "before": "h = date.hour(time, \"IST\")",
        "after": "h = date.hour(time, \"Asia/Kolkata\")"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/stdlib/calendar.test.ts"
    },
    {
      "code": "OS6006",
      "title": "The engine lacks a capability the program requires",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "This program requires {tag} and this engine does not have it.",
      "placeholders": {
        "tag": "the first required capability tag the engine does not have"
      },
      "cause": "A compiled program lists the capability tags it needs, and the engine compares the list against its own at load. Tags are the real compatibility mechanism and the format version is the coarse one. Refusing at load is better than meeting an instruction the engine cannot execute halfway through a bar, with half a chart already drawn.",
      "fix": "Run the program on an engine that has {tag}, or remove the feature that needs it: the tag names it.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "program requires: core.1, arrays, orders\nengine has:       core.1, arrays",
        "after": "program requires: core.1, arrays\nengine has:       core.1, arrays"
      },
      "spec": "compiled-program.md, capability tags",
      "refines": null,
      "test": "tests/engine/verify.test.ts"
    },
    {
      "code": "OS6007",
      "title": "Unknown symbol or exchange",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The host does not know {symbol} on {exchange}.",
      "placeholders": {
        "symbol": "the symbol that was requested",
        "exchange": "the exchange that was requested, or the chart's when none was given"
      },
      "cause": "A symbol is resolved by the host against the instruments it can serve. An unknown one is reported rather than returning an empty series, because an empty series looks exactly like an instrument that did not trade.",
      "fix": "Correct the symbol, and name the exchange it trades on when it is not the chart's: req.symbol(\"SYMBOL\", \"1D\", close, exchange = \"EXCHANGE\").",
      "autofix": false,
      "example": {
        "before": "other = req.symbol(\"SYMBL\", \"1D\", close)",
        "after": "other = req.symbol(\"SYMBOL\", \"1D\", close, exchange = \"EXCHANGE\")"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/hosts/host.ts"
    },
    {
      "code": "OS6008",
      "title": "The request returned no bars",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "{symbol} at {timeframe} returned no bars over the range this chart covers.",
      "placeholders": {
        "symbol": "the symbol that was requested",
        "timeframe": "the interval that was requested"
      },
      "cause": "The host resolved the instrument and had nothing to send for the range. An instrument that had not listed yet, a contract that has expired and a range before the stored history begins all arrive here.",
      "fix": "Move the chart's range into the period the instrument traded, or request a symbol that covers it.",
      "autofix": false,
      "example": {
        "before": "fut = req.symbol(\"EXPIRED_CONTRACT\", \"1D\", close)",
        "after": "fut = req.symbol(\"CURRENT_CONTRACT\", \"1D\", close)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/hosts/host.ts"
    },
    {
      "code": "OS6009",
      "title": "The request failed",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The host could not fetch {symbol} at {timeframe}: {reason}.",
      "placeholders": {
        "symbol": "the symbol that was requested",
        "timeframe": "the interval that was requested",
        "reason": "the host's own description of the failure"
      },
      "cause": "The host reached its data source and the source refused or did not answer. A connection that is down, a subscription that does not cover the instrument and a rate limit all arrive here, carrying the reason the host gave.",
      "fix": "Act on {reason} in the host: it is a connection, permission or quota problem. Where the value can be derived from the chart's own bars, derive it and drop the request.",
      "autofix": false,
      "example": {
        "before": "dayHigh = req.timeframe(\"1D\", high)",
        "after": "var dayHigh = none\nif session.isFirstBar\n    dayHigh = high\nelse\n    dayHigh = max(dayHigh, high)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/engine/requests-host.test.ts"
    },
    {
      "code": "OS6010",
      "title": "The engine was given no bars",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "There are no bars for {symbol} at {timeframe}, so the script cannot run.",
      "placeholders": {
        "symbol": "the chart's symbol",
        "timeframe": "the chart's interval"
      },
      "cause": "The script is the body of the per-bar loop, and a loop over zero bars produces nothing to plot and nothing to report. Saying so is better than an empty pane, which looks like a script that computed nothing.",
      "fix": "Choose an instrument and interval that have history, or widen the chart's date range until bars exist.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "host input: symbol SYMBOL, interval 5, bars 0",
        "after": "host input: symbol SYMBOL, interval 5, bars 1240"
      },
      "spec": "language.md 7.1",
      "refines": null,
      "test": "tests/engine/series.test.ts"
    },
    {
      "code": "OS6011",
      "title": "The bars are not in order",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "Bar {index} is dated {time}, which is not after bar {previous}.",
      "placeholders": {
        "index": "the index of the offending bar",
        "time": "that bar's timestamp",
        "previous": "the index of the bar before it"
      },
      "cause": "Every engine assumes strictly increasing bar times: the history operator, warmup and every session test are defined against that order. Running on duplicated or reversed bars would make every one of those meaningless, quietly.",
      "fix": "Reload the history; if the same bar repeats, the feed is sending duplicates and the host has to sort and deduplicate the bars before the engine runs.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "host input:\n  bar 41  09:15\n  bar 42  09:15\n  bar 43  09:10",
        "after": "host input:\n  bar 41  09:10\n  bar 42  09:15\n  bar 43  09:20"
      },
      "spec": "language.md 7.1",
      "refines": null,
      "test": "tests/engine/series.test.ts"
    },
    {
      "code": "OS6012",
      "title": "An instrument fact is not known",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The host did not supply {fact} for {symbol}.",
      "placeholders": {
        "fact": "what the instrument record lacks for something that cannot default it: a timezone for the session it states, a timezone the calendar can read, a session spelled HH:MM, or session days numbered 1 to 7",
        "symbol": "the instrument it is missing for"
      },
      "cause": "An instrument fact the host did not state is absent, and a bare read of one, chart.tickSize or chart.lotSize among them, returns the absent value a script can test with isNone (stdlib.md 3.4). This error is the other case: something that needs the fact and has no way to proceed without it. A session with no timezone is a window with no clock to read it in, so every session test on that host would answer absence on every bar and every session study would draw nothing with nothing said. The engine refuses the record at load instead, before any bar runs, because the fact comes from the instrument record (host-interface.md 4.1) and not from the bars, and a guessed zone is silently wrong for half the year anywhere a clock changes with the season.",
      "fix": "Supply {fact} in the host's instrument record for {symbol}, or leave the session out of the record, which makes every session read absent rather than wrong.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "host instrument record:\n  session   09:15 to 15:30, days 1 to 5\n  timezone  not stated",
        "after": "host instrument record:\n  session   09:15 to 15:30, days 1 to 5\n  timezone  UTC"
      },
      "spec": "host-interface.md 4.5",
      "refines": null,
      "test": "tests/engine/requests-host.test.ts"
    },
    {
      "code": "OS6013",
      "title": "The request changed after the first bar",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "This request asked for {first} on bar 0 and for {found} on bar {bar}.",
      "placeholders": {
        "first": "the symbol and timeframe requested on the first bar",
        "found": "the symbol and timeframe requested on this bar",
        "bar": "the bar index where it changed"
      },
      "cause": "The host fetches a requested series once, keyed by symbol and timeframe, and keeps it in step with the chart. A request whose identity changes mid-run would need a second fetch on a bar that has already been drawn, so the identity is fixed before the run.",
      "fix": "Compute the symbol and the timeframe from literals or inputs, not from bar data.",
      "autofix": false,
      "example": {
        "before": "tf = close > open ? \"60\" : \"1D\"\nh = req.timeframe(tf, high)",
        "after": "tf = input(\"60\", \"Higher timeframe\", kind = \"interval\")\nh = req.timeframe(tf, high)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. A read's identity is settled once before bar 0 and nothing asks again, so there is no second identity for the engine to compare the first one against. Raised when the engine resolves a read's identity per bar, language.md 15.2."
    },
    {
      "code": "OS6014",
      "title": "The feed does not offer this timeframe",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The host has no {timeframe} data for {symbol}; it offers {available}.",
      "placeholders": {
        "timeframe": "the interval that was requested",
        "symbol": "the instrument it was requested for",
        "available": "the intervals the host can serve for it"
      },
      "cause": "A timeframe can be well formed and still be one the feed does not store for this instrument. Building it from a lower one is the host's decision to offer or not, and the script is told which intervals exist rather than receiving a silently empty series.",
      "fix": "Request one of {available}, or derive the interval you want from a lower one the host does serve.",
      "autofix": false,
      "example": {
        "before": "r = req.timeframe(\"3\", close)",
        "after": "r = req.timeframe(\"5\", close)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/hosts/reads.ts"
    },
    {
      "code": "OS6015",
      "title": "The requested timeframe does not fold into the chart's",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "{requested} is not a whole multiple of {chart}.",
      "placeholders": {
        "requested": "the interval that was requested",
        "chart": "the chart's interval",
        "suggestion": "the nearest interval above the requested one that is a whole multiple of the chart's"
      },
      "cause": "An intraday request is folded by counting chart bars, so its interval must be a whole multiple of the chart's. Day, week and month requests are folded by the calendar instead, keyed by the civil date in the instrument's timezone, so they are exempt from this rule.",
      "fix": "Request a multiple of {chart}, for example {suggestion}.",
      "autofix": false,
      "example": {
        "before": "r = req.timeframe(\"45\", close)",
        "after": "r = req.timeframe(\"60\", close)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/engine/requests-load.test.ts"
    },
    {
      "code": "OS6016",
      "title": "The compiled format version is not one this engine implements",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "This program is in compiled format {found} and this engine implements format {max}; a different major number is a different format, whether it is higher or lower.",
      "placeholders": {
        "found": "the format version the program declares",
        "max": "the format version this engine implements"
      },
      "cause": "The compiled program is a versioned data format, and an engine refuses a format it cannot read rather than guessing at instructions it does not know. Only the major number decides. A higher minor loads, because a minor addition whose absence would change a number has to announce itself as a tag in the program's requires list, and an older minor loads because it carries a subset of the fields this engine already reads. A major number that is not this engine's is a different format wearing the same name, so it is refused in both directions: a program older than this engine is refused for the same reason as one newer, and neither is run approximately. Refusing at load, with both numbers named, is the whole reason the version is carried.",
      "fix": "Run the program on an engine that implements format {found}, or recompile the source with a compiler that emits format {max}.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "program: compiled format 0.9\nengine:  compiled format 1.0",
        "after": "program: compiled format 1.0\nengine:  compiled format 1.0"
      },
      "spec": "compiled-program.md, loading a program",
      "refines": null,
      "test": "tests/engine/verify.test.ts"
    },
    {
      "code": "OS6017",
      "title": "The program's language version is not one this engine implements",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "This program was compiled from language version {found}, and this engine implements {versions}.",
      "placeholders": {
        "found": "the language version the program declares",
        "versions": "the language versions the engine implements"
      },
      "cause": "Every past front end is kept, so a program may name a language version older than the engine and still run exactly as it did. A version the engine does not have is one it cannot run correctly, and running it approximately would break the promise that a saved script keeps producing the same numbers.",
      "fix": "Upgrade the engine to one that implements language version {found}, or recompile the source against a version it has.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "program: language version 2\nengine:  language version 1",
        "after": "program: language version 1\nengine:  language version 1"
      },
      "spec": "language.md 4.1",
      "refines": null,
      "test": "tests/engine/verify.test.ts"
    },
    {
      "code": "OS6018",
      "title": "The compiled program is malformed",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The program failed verification at {location}: {reason}.",
      "placeholders": {
        "location": "where the failure is: the word instruction followed by the index of the first instruction that failed, or, when the failure is not in an instruction list, the path of the field that failed, such as outputs[3].color",
        "reason": "what the verifier found wrong there"
      },
      "cause": "An engine verifies a program before it runs it: the encoding parses, every jump lands inside the program, every slot is in range, and every instruction's operands are the shape the format requires. A program that fails is refused whole, because one that is verified as it goes can fail halfway through a bar with half a chart already drawn. Not every check is about an instruction: the structure checks read the program's own fields, and the input-reference check fails on a declaration field that names an input the program never declares, so a failure is located either at the first instruction that failed or at the field holding it, and the message carries whichever of the two applies.",
      "fix": "Recompile the script from its source; a program that fails verification came from a broken compiler or was edited after it was written, and neither is repairable by hand.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "instruction 402: JUMP target 9911, program holds 812 instructions",
        "after": "instruction 402: JUMP target 411, program holds 812 instructions"
      },
      "spec": "compiled-program.md 3.5, 9.4",
      "refines": null,
      "test": "tests/engine/verify.test.ts"
    },
    {
      "code": "OS6019",
      "title": "A host setting fails the input's validation",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The host supplied {value} for {key}, and {validation}.",
      "placeholders": {
        "value": "the value the host supplied",
        "key": "the input's settings key",
        "validation": "the rule it broke, such as the minimum being 1"
      },
      "cause": "An input validates exactly what the host supplies: the type, a number's min and max, and membership of an options list. A value that fails is refused and the program does not run, rather than falling back to the default, because a settings dialog that silently ignores what a user typed is worse than one that says the value is out of range. A declaration field that the compiled program carries as a reference to an input arrives here on the same ground: the engine resolves inputs at load and substitutes the value before it builds the descriptor, so a resolved value the field refuses is a setting from outside the source that the program cannot run with.",
      "fix": "Correct the value in the settings dialog, or widen the input's own min, max or options so the value is allowed.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "input len: min 1, max 500\nhost setting: len = 0",
        "after": "input len: min 1, max 500\nhost setting: len = 14"
      },
      "spec": "language.md 13.4",
      "refines": null,
      "test": "tests/engine/verify.test.ts"
    },
    {
      "code": "OS6020",
      "title": "The report window holds no bars",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The window from {from} to {to} holds none of the {count} bars supplied.",
      "placeholders": {
        "from": "the first moment the window covers, or the first bar supplied where the host named none",
        "to": "the last moment it covers",
        "count": "how many bars were supplied"
      },
      "cause": "A report is about the bars inside the window the host chose, and a window holding none of them has nothing to report: no equity point, no trade and no summary. The bars outside it are warmup, which execute and whose orders are real, so an empty window is not an empty run, and reporting one as a flat curve would tell a reader that nothing happened when something did.",
      "fix": "Widen the window until it covers bars, or supply the bars it covers. Both bounds are inclusive and are compared against the times of the bars supplied rather than against a calendar, so a window that falls inside a gap in the data is empty however wide it looks.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "bars supplied: 1240, first day 1, last day 1240\nreport window: day 1300 to day 1400, bars inside 0",
        "after": "bars supplied: 1240, first day 1, last day 1240\nreport window: day 1100 to day 1240, bars inside 141"
      },
      "spec": "language.md 7.1",
      "refines": null,
      "test": "tests/backtest/range.test.ts"
    },
    {
      "code": "OS6021",
      "title": "A run setting cannot be applied as stated",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "{setting} cannot be applied: {problem}.",
      "placeholders": {
        "setting": "the setting that cannot be applied, such as the charge schedule or the comparison tolerance",
        "problem": "what makes it unusable, such as a charge line levied on a line declared after it"
      },
      "cause": "A run states the settings it is carried out under before its first bar, and a setting that cannot be carried out is refused there rather than quietly producing a figure. A charge line levied on lines not declared before it has no single evaluation order, so two engines would charge two different amounts and both would be defensible. A slippage stated in ticks with no tick size to measure a tick in would charge nothing at all, which is a backtest that lies in the strategy's favour. A comparison tolerance carrying a bound and no reason is a failed comparison somebody switched off, and one past the cap conformance.md section 6 puts on a declared tolerance is a comparison the suite will not accept, so a run that declared one is refused a case rather than written into one that fails every runner it meets.",
      "fix": "State the setting so it can be carried out: declare a charge line after every line it is levied on, supply the tick size a slippage in ticks is measured in, write down the reason a tolerance needs a bound, or bring a bound past the cap back inside it. Nothing has been computed at the point this is refused, so correcting the setting and running again costs one run.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "charge lines: tax on levy, levy\nslippage: 2 ticks, tick size not supplied",
        "after": "charge lines: levy, tax on levy\nslippage: 2 ticks, tick size 0.05"
      },
      "spec": "stdlib.md 17.1",
      "refines": null,
      "test": "tests/accounting/schedules.test.ts"
    },
    {
      "code": "OS6022",
      "title": "The bars are not the bars the record was made from",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The bars supplied hash to {found}, and the record was made from {expected}.",
      "placeholders": {
        "found": "the hash of the bars supplied now",
        "expected": "the hash the record names"
      },
      "cause": "A record names the bars it was made from by a hash over their canonical form, so a replay can prove it is replaying the same run rather than producing a different study under the same name. Bars are revised: a feed corrects a print, a session is extended, a split is applied to history. A replay over revised bars that reported the original figures would be the most convincing wrong answer this system can produce.",
      "fix": "Replay against the bars the record names. Where the revision is the point, make a second record over the revised bars and compare the two runs, rather than overwriting one run with the other under one name.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "record: bars 1240, hash 9f2c4e...\nsupplied: bars 1240, hash 4ab70d...",
        "after": "record: bars 1240, hash 9f2c4e...\nsupplied: bars 1240, hash 9f2c4e..."
      },
      "spec": "conformance.md 3",
      "refines": null,
      "test": "tests/backtest/record.test.ts"
    },
    {
      "code": "OS6023",
      "title": "Two cost models are stated at once",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "A charge schedule was supplied, and the declaration states a commission of {commission} in {commissionType}.",
      "placeholders": {
        "commission": "the commission the declaration states",
        "commissionType": "the unit that commission is stated in"
      },
      "cause": "The declaration's commission is the script's own statement of what trading costs and a supplied schedule is the platform's, and the two describe the same money. Applied together they charge it twice; applied one at a time they charge whichever an engine happened to prefer, which is a rule nobody wrote down and a figure nobody can explain afterwards. So exactly one of the two is stated for a run, and stating both is refused before the first bar rather than reconciled behind the reader.",
      "fix": "Supply the schedule and leave the declaration's commission at its default of zero, or state the commission in the declaration and supply no schedule. A schedule is the one of the two that can carry a floor, a cap, a charge levied on a charge, and a cost that falls on one side of the trade only.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "declaration: commission 20, per trade\nhost: charge schedule supplied, 4 lines",
        "after": "declaration: commission 0, per trade\nhost: charge schedule supplied, 4 lines"
      },
      "spec": "language.md 13.3; stdlib.md 17.1",
      "refines": null,
      "test": "tests/backtest/settings.test.ts"
    },
    {
      "code": "OS6024",
      "title": "The host cannot draw something this study declares",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "This host cannot draw {what}: {limit}.",
      "placeholders": {
        "what": "the declaration that will not be drawn, named by its title where it has one",
        "limit": "the host's own sentence for why, which is the only part a host writes"
      },
      "cause": "A compiled program carries every output the language can express, and a host draws what its own surface has room for. The two are allowed to differ, and what is not allowed is the difference being invisible: a study whose second panel never appears looks like a study with a bug in its cells, and a band drawn in a colour the script did not choose looks like a script that chose it. So a host states its limit before any bar runs, rather than drawing part of the study and saying nothing. The compiled program carries no source position for a declaration, which is why the refusal names the declaration by its title rather than pointing at a line.",
      "fix": "Declare what this host draws, or run the study on a host that draws {what}.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "study declares:\n  table \"Summary\", 2 rows, 2 columns\n  table \"Detail\", 4 rows, 2 columns\nhost draws: one grid per pane",
        "after": "study declares:\n  table \"Summary\", 6 rows, 2 columns\nhost draws: one grid per pane"
      },
      "spec": "compiled-program.md 11",
      "refines": null,
      "test": "tests/adapters/charts/undrawable.test.ts"
    },
    {
      "code": "OS6025",
      "title": "A bar has no time",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "Bar {index} was handed over with no time.",
      "placeholders": {
        "index": "the index of the bar that carries no time"
      },
      "cause": "Every bar states its open instant (host-interface.md 3.1), and the order rule, the history operator, warmup and every calendar fold are built on it. A bar dated nothing cannot be put in order against the bar before it, so it is not OS6011, which is about two stated instants in the wrong order: it is a bar of the wrong shape. Reading it as the absent value would step it over every calendar fold and make every session fact absent for a bar that is on the chart, which draws a gap where the host has data.",
      "fix": "State the bar's open instant in whole milliseconds since the Unix epoch, UTC, and leave out a bar the host cannot date rather than handing it over without a time.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "host input:\n  bar 41  09:10\n  bar 42  (no time)\n  bar 43  09:20",
        "after": "host input:\n  bar 41  09:10\n  bar 42  09:15\n  bar 43  09:20"
      },
      "spec": "host-interface.md 3.5",
      "refines": null,
      "test": "tests/engine/series.test.ts"
    },
    {
      "code": "OS7001",
      "title": "Only a strategy can do that",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} is available only in a file declared with strategy().",
      "placeholders": {
        "name": "the order function or position name that was used",
        "line": "the line of the study declaration"
      },
      "cause": "Order functions and the pos namespace need a position to act on and a report to write to, both of which a study does not have. The check is at compile time so a study can never place an order at all.",
      "fix": "Change study(...) on line {line} to strategy(...), or replace {name} with signal(\"...\") to mark the bar without trading.",
      "autofix": false,
      "example": {
        "before": "study(\"EMA cross\", overlay = true)\n\nif crossUp(fast, slow)\n    buy(qty = 1)",
        "after": "strategy(\"EMA cross\", overlay = true)\n\nif crossUp(fast, slow)\n    buy(qty = 1)"
      },
      "spec": "language.md 13.1, 13.3",
      "refines": null,
      "test": "tests/unit/check-names.test.ts"
    },
    {
      "code": "OS7002",
      "title": "An order argument is absent",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{name}'s {argument} is absent on this bar.",
      "placeholders": {
        "name": "the order function that was called",
        "argument": "the argument that was absent"
      },
      "cause": "An order is the one place in the language where doing nothing quietly is worse than stopping loudly, so an absent price or quantity is refused rather than defaulted. Warmup is the usual source: a stop computed from a window that has not filled yet.",
      "fix": "Guard the call with isNone({argument}), or supply a fallback with orElse() where one is genuinely correct.",
      "autofix": false,
      "example": {
        "before": "buy(qty = 1, stop = lowest(low, 20))",
        "after": "s = lowest(low, 20)\nif not isNone(s)\n    buy(qty = 1, stop = s)"
      },
      "spec": "language.md 6.8",
      "refines": null,
      "test": "tests/engine/refusals.test.ts"
    },
    {
      "code": "OS7003",
      "title": "An order function inside a request expression",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "{name} inside a request expression would place an order from another instrument's bars.",
      "placeholders": {
        "name": "the order function that was called inside the expression"
      },
      "cause": "A request expression is evaluated on the requested instrument's bars, in that instrument's time. An order placed there has no defined instrument, no defined moment and no defined price, and it would fire once per bar of a series the chart never shows.",
      "fix": "Read the value with the request, and place the order at the top level from the result.",
      "autofix": false,
      "example": {
        "before": "d = req.timeframe(\"1D\", buy(qty = 1))",
        "after": "up = req.timeframe(\"1D\", close > ema(close, 20))\nif up\n    buy(qty = 1)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": "tests/unit/check-repaint.test.ts"
    },
    {
      "code": "OS7004",
      "title": "Order quantity is zero or negative",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{name} was given a quantity of {qty}.",
      "placeholders": {
        "name": "the order function that was called",
        "qty": "the quantity that reached it"
      },
      "cause": "Direction is chosen by the function, not by the sign of the quantity, so a negative quantity is a calculation that went the wrong way rather than an order in the other direction. A quantity of zero is never what a script means.",
      "fix": "Pass a positive quantity, guard the call with a size test, and use sell() to go the other way.",
      "autofix": false,
      "example": {
        "before": "buy(qty = target - pos.size)",
        "after": "delta = target - pos.size\nif delta > 0\n    buy(qty = delta)"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": "tests/engine/refusals.test.ts"
    },
    {
      "code": "OS7005",
      "title": "Quantity is not a multiple of the lot size",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{symbol} trades in lots of {lot}, and {qty} is not a multiple of it.",
      "placeholders": {
        "symbol": "the instrument being traded",
        "lot": "its lot size",
        "qty": "the quantity that was passed"
      },
      "cause": "An exchange that trades in lots rejects anything else, so a backtest that filled such an order would report a trade that could not have happened. The engine refuses it for the same reason the exchange would.",
      "fix": "Size in lots: declare qtyType = \"lots\" and pass the lot count, or round a computed size with order.roundToLot().",
      "autofix": false,
      "example": {
        "before": "buy(qty = 100)",
        "after": "strategy(\"Lots\", qtyType = \"lots\")\nbuy(qty = 2)"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": "tests/engine/ending.test.ts",
      "deferred": "Nothing raises this yet. Nothing compares an order's quantity with the lot size its leg trades in, so a quantity no exchange would accept is sent and a backtest can report a trade that could not have happened. The same missing fact is what leaves two other shapes of stdlib.md 17.1 unheld, and all three are settled together. A quantity stated on a close in a declaration counting in lots, cash or an equity percent cannot be held against a position folded in units, which is the narrowing OS7017 carries. And an order that opposes what the leg holds in such a declaration cannot be divided into the half that closes the outgoing position and the half that opens its replacement, so it is sent whole. What is kept without the lot size, and kept in every unit: it is sent on a position reference of its own, whether or not anything has settled, so that it crosses nothing; and the outgoing position is named again, because a close works its own quantity out in units and is divided across the positions holding the leg's own side, oldest first, so that position returns to zero as soon as the leg's net comes back to its side. What is not kept is the instruction itself closing it. The outgoing position is left holding what it holds, and on a leg whose net never returns to that side it is carried for the life of the run with no order able to name it. Raised when order validation lands, stdlib.md 17.2, which is also when the ledger is given the lot size its leg trades in."
    },
    {
      "code": "OS7006",
      "title": "Price is not on a tick",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{symbol} ticks at {tick}, and {price} does not fall on one.",
      "placeholders": {
        "symbol": "the instrument being traded",
        "tick": "its tick size",
        "price": "the price that was passed"
      },
      "cause": "A limit or stop price between two ticks cannot exist at the exchange. Rounding it silently would move the order away from the level the script computed, and in a backtest that difference is free money or a free stop.",
      "fix": "Round to the tick before passing the price: round(price / chart.tickSize) * chart.tickSize.",
      "autofix": false,
      "example": {
        "before": "sell(qty = 1, limit = close * 1.013)",
        "after": "target = round(close * 1.013 / chart.tickSize) * chart.tickSize\nsell(qty = 1, limit = target)"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": "tests/engine/refusals.test.ts"
    },
    {
      "code": "OS7007",
      "title": "A resting order has no price",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "A {type} order needs {argument}, and none was given.",
      "placeholders": {
        "type": "the order type that was named",
        "argument": "the price argument that is missing"
      },
      "cause": "An order that rests in the book needs the level it rests at. Filling it in from the bar's close would make the order a market order wearing another name, and the report would show a fill the script never asked for.",
      "fix": "Pass {argument}, or leave the type as market and let the order fill at the next price.",
      "autofix": false,
      "example": {
        "before": "order.place(\"buy\", 1, type = \"limit\")",
        "after": "order.place(\"buy\", 1, type = \"limit\", price = close - chart.tickSize)"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": "tests/engine/refusals.test.ts"
    },
    {
      "code": "OS7008",
      "title": "The entry was refused by pyramiding",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "This strategy allows {max} entries in one direction and already holds {found}.",
      "placeholders": {
        "max": "the pyramiding option in force",
        "found": "the number of entries already open in that direction"
      },
      "cause": "Refusing rather than silently adding keeps a backtest from building a position the declaration forbade, which would report a return the stated rules never earned.",
      "fix": "Raise pyramiding in the declaration, or test pos.size before entering again.",
      "autofix": false,
      "example": {
        "before": "strategy(\"Add\", pyramiding = 1)\nif signalUp\n    buy(qty = 1)",
        "after": "strategy(\"Add\", pyramiding = 1)\nif signalUp and pos.size == 0\n    buy(qty = 1)"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": "tests/engine/refusals.test.ts"
    },
    {
      "code": "OS7009",
      "title": "Unknown order tag",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "There is no working order tagged {tag}.",
      "placeholders": {
        "tag": "the tag that was passed"
      },
      "cause": "A tag names an order from the moment it is placed. Acting on a tag that names nothing is a script that has lost track of its own orders, and ignoring the call would leave it believing an order exists that does not. This code is for a call that acts on an order. The reading calls of stdlib.md section 17.3 read the ledger, which keeps a row after the order finishes, so a tag that names no row reads as the entry's documented empty value rather than raising.",
      "fix": "Use the tag the order was placed with, or cancelAll() where the script means every order it has working.",
      "autofix": false,
      "example": {
        "before": "buy(qty = 1, tag = \"entry\")\ncancel(\"entries\")",
        "after": "buy(qty = 1, tag = \"entry\")\ncancel(\"entry\")"
      },
      "spec": "language.md 15.2; stdlib.md 17.3",
      "refines": null,
      "test": "tests/engine/tags.test.ts"
    },
    {
      "code": "OS7010",
      "title": "A bracket price is on the wrong side of the entry",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "A {side} entry at {entry} cannot take a {leg} at {price}.",
      "placeholders": {
        "side": "long or short",
        "entry": "the position's average entry price",
        "leg": "the bracket leg: stop or limit",
        "price": "the price that was passed"
      },
      "cause": "A stop protects and a limit takes profit, so their sides are fixed by the direction of the position. A stop on the wrong side fills immediately, which in a backtest turns every trade into an instant loss that looks like a strategy result.",
      "fix": "Put the stop below a long entry and the limit above it, and swap the two for a short.",
      "autofix": false,
      "example": {
        "before": "if pos.isFlat\n    buy(qty = 1)\nelse\n    exit(limit = pos.avgPrice - atrValue, stop = pos.avgPrice + atrValue)",
        "after": "if pos.isFlat\n    buy(qty = 1)\nelse\n    exit(limit = pos.avgPrice + atrValue, stop = pos.avgPrice - atrValue)"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": "tests/engine/refusals.test.ts"
    },
    {
      "code": "OS7011",
      "title": "The order needs more capital than the strategy has",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "This order needs {required} and the strategy has {available}.",
      "placeholders": {
        "required": "the capital the order would consume",
        "available": "the capital the strategy has left"
      },
      "cause": "A backtest that can spend money it does not have reports a return nobody could have earned. The order is refused rather than filled on credit, and the report records the refusal so the equity curve stays honest.",
      "fix": "Size from equity with qtyType = \"equityPercent\", or test pos.equity before entering.",
      "autofix": false,
      "example": {
        "before": "buy(qty = 100)",
        "after": "strategy(\"Sized\", qtyType = \"equityPercent\")\nbuy(qty = 10)"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. Nothing compares an order's cost with the capital the strategy has, so a backtest can spend money it never had and report a return nobody could have earned. Raised when the ledger holds a capital figure to check against, language.md 13.3."
    },
    {
      "code": "OS7012",
      "title": "The instrument is outside its session",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{symbol} is outside its trading session at {time}.",
      "placeholders": {
        "symbol": "the instrument being traded",
        "time": "the bar's timestamp"
      },
      "cause": "An order placed outside the session cannot be worked by the exchange. Holding it until the open would fill it at a price the script never saw, so it is refused and the script decides what to do at the open instead.",
      "fix": "Guard entries with session.isOpen, and set closeOnSessionEnd = true to flatten at the close.",
      "autofix": false,
      "example": {
        "before": "if crossUp(fast, slow)\n    buy(qty = 1)",
        "after": "if crossUp(fast, slow) and session.isIn(\"0915-1530\")\n    buy(qty = 1)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. Nothing compares the bar's time with the instrument's session before an order is sent, so an order outside the session leaves the engine as though the venue were open. Raised when order validation reads the session, language.md 15.2."
    },
    {
      "code": "OS7013",
      "title": "Two opposite orders on one bar",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "{first} and {second} were both placed on bar {bar}.",
      "placeholders": {
        "first": "the first order call, with its line",
        "second": "the second order call, with its line",
        "bar": "the bar index"
      },
      "cause": "Which of the two the engine should honour has no defensible answer: source order is an accident of layout, and the last one wins is a rule that silently changes when someone reorders two blocks. Neither is placed, and the bar stops.",
      "fix": "Make the conditions exclusive with else if, or place the exit on this bar and the entry on the next.",
      "autofix": false,
      "example": {
        "before": "r = rsi(close, 14)\nif crossUp(fast, slow)\n    buy(qty = 1)\nif r > 70\n    sell(qty = 1)",
        "after": "r = rsi(close, 14)\nif crossUp(fast, slow)\n    buy(qty = 1)\nelse if r > 70\n    sell(qty = 1)"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": "tests/engine/refusals.test.ts"
    },
    {
      "code": "OS7014",
      "title": "The destination rejected the order",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The order destination rejected {name}: {reason}.",
      "placeholders": {
        "name": "the order function that was called",
        "reason": "the destination's own rejection text"
      },
      "cause": "The order left the engine well formed and the destination refused it. A product the account cannot trade, a margin shortfall and a symbol the account has no permission for all arrive here, carrying the destination's reason.",
      "fix": "Act on {reason}: it comes from the destination, not from the script, and the same order will be rejected again until the account or the order changes.",
      "autofix": false,
      "example": {
        "before": "strategy(\"Swing\", product = \"overnight\")\nbuy(qty = 1)",
        "after": "strategy(\"Swing\", product = \"intraday\")\nbuy(qty = 1)"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. A refusal that comes back is folded into the ledger row as a status and its text, and no diagnostic is raised, so nothing reports it against the line that placed the order. Raised when a refused fold reports, stdlib.md 17.8."
    },
    {
      "code": "OS7015",
      "title": "The strategy has no order destination",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "This strategy placed an order and the host supplied no destination.",
      "placeholders": {},
      "cause": "A strategy needs somewhere for orders to go: a sandbox engine, a backtest simulator or a broker connection. Running one with no destination would compute a position nothing ever took.",
      "fix": "Connect a destination in the host, or run the file as a study(): replace buy() with signal(\"BUY\").",
      "autofix": false,
      "example": {
        "before": "strategy(\"EMA cross\")\nif crossUp(fast, slow)\n    buy(qty = 1)",
        "after": "study(\"EMA cross\")\nif crossUp(fast, slow)\n    signal(\"BUY\")"
      },
      "spec": "language.md 13.3",
      "refines": null,
      "test": "tests/hosts/strategy.test.ts",
      "deferred": "Nothing raises this yet. A strategy with nowhere to send orders is not stopped: it places intents that reach nobody, and nothing says so. Raised when the engine checks for a destination before the first order, host-interface.md 7.4."
    },
    {
      "code": "OS7016",
      "title": "A close names a tag nothing places",
      "severity": "error",
      "stage": "check",
      "since": 1,
      "message": "No order in this file is placed with the tag {tag}.",
      "placeholders": {
        "tag": "the tag the close was given"
      },
      "cause": "A close names the part of a position that one tag entered. A tag no order in the file is placed with can never name a part of one, so the call sends nothing on every bar and says nothing, and the script goes on believing it has flattened. It is read from the file rather than from the run because the run cannot tell this from an ordinary bar: a tag that has never named a ledger row is also what a working script looks like before its entry has happened. A tag the script computes is not read, and neither is any close in a file where an order's tag is computed.",
      "fix": "Use the tag the entry was placed with, or leave the tag out to flatten the whole leg.",
      "autofix": false,
      "example": {
        "before": "if pos.isFlat\n    buy(qty = 1, tag = \"entry\")\nelse\n    close(tag = \"entries\")",
        "after": "if pos.isFlat\n    buy(qty = 1, tag = \"entry\")\nelse\n    close(tag = \"entry\")"
      },
      "spec": "stdlib.md 17.2",
      "refines": null,
      "test": "tests/unit/check-tags.test.ts"
    },
    {
      "code": "OS7017",
      "title": "A close states more than it is closing",
      "severity": "error",
      "stage": "runtime",
      "since": 1,
      "message": "close was given a quantity of {qty}, and {part} has {held} left to close.",
      "placeholders": {
        "qty": "the quantity the call stated",
        "part": "what the close is closing: the leg, or the tag it named",
        "held": "what is left for a close to send: what that part holds, less what is already working against it"
      },
      "cause": "No order crosses zero, and a reducing order can never send more than is available to reduce. A close larger than what is left to close sends one order that flattens the position and opens the opposite one under the same position reference, so a leg that was long ends short and a call named close has opened a position. The quantity is an argument the script wrote, which makes it a claim about the strategy's own position, and this claim is false. Sending what is there instead would leave the script believing it closed the number it asked for, and reading it as a reversal would make close open a position, which is the most expensive naming mistake available. What is left to close is what the leg holds, or what the tag the close names holds, less everything already working against it. A position is folded from settled fills, so an order the destination has not answered has filled nothing and the leg still reads what it held before that order left: measured against that alone, two closes of two on a leg of three each pass the ceiling and the pair ends the leg one short, and a close on every bar against a destination that never answers ends the run short by the position once per bar. The scope is therefore the run and the position rather than the bar, and what is still working is read from the ledger of stdlib.md 17.7: an order neither terminal nor fully filled, counted by the part of it that has not filled. A rejection, a cancellation and an expiry release what they were holding, because nothing more is coming from an order that has ended. What is counted is every order still going on the side that reduces what the leg holds now, and not only the ones that were reductions when they left: an entry the destination has not answered, on a leg the orders after it took the other way, is a reduction now, and leaving it out offered a close the whole of a position five units of which were already on their way. A close that states no quantity is not this: the engine works out what is left and sends it, which is nothing at all once the whole of it is going, and closing a tag that holds nothing sends nothing and says nothing. The comparison is made in full only where the two numbers count the same thing, which is a declaration whose quantity type is units: elsewhere a position folded from filled quantities and a quantity stated in the declaration's own unit are two different kinds of number, and a refusal with the wrong one in it is worse than none. The half of it that needs no conversion is made whatever the declaration counts in, because nothing left to close is zero in every unit. What that leaves unheld is one shape, a quantity stated against a position that is still there in a declaration counting in lots, cash or an equity percent, and joining those two numbers needs the instrument's lot size, which is the fact OS7005 is deferred on.",
      "fix": "Leave the quantity out and close() flattens what is left, or size the part from pos.size and keep the quantity at or under {held}.",
      "autofix": false,
      "example": {
        "before": "if pos.isFlat\n    buy(qty = 1)\nelse\n    close(qty = 5)",
        "after": "if pos.isFlat\n    buy(qty = 1)\nelse\n    close()"
      },
      "spec": "stdlib.md 17.1, 17.2",
      "refines": null,
      "test": "tests/engine/closing.test.ts"
    },
    {
      "code": "OS7018",
      "title": "A frame names an order this strategy did not place",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The frame names intent {intent}, and this strategy holds no such order.",
      "placeholders": {
        "intent": "the intent id the frame named"
      },
      "cause": "Step 1 of the fold locates the row a frame is about, and a frame naming no row cannot be folded into anything. It is a fact about the host rather than about the strategy: a destination answering for an order another strategy placed, or answering for a run that has already ended. The frame changes nothing and is reported, because a fold that passed over it in silence would leave a host's mistake invisible to the only party who can correct it.",
      "fix": "Answer with the intent id the engine sent. A destination's own reference is carried in the frame's reference field, where the engine records it and never parses it, and it is not what an answer is addressed by.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "engine sent: intent 7, intent 8\nframe: intent 11, status filled, filled qty 1",
        "after": "engine sent: intent 7, intent 8\nframe: intent 8, status filled, filled qty 1"
      },
      "spec": "stdlib.md 17.8, 17.14",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. The fold refuses the frame and records the refusal as a word on the outcome it hands back, and a word is not a catalogue code, so nothing reports it against the run and a host answering for orders it was never handed stays invisible. Raised when the outcome of a fold carries a code and a bar carries a channel for a diagnostic that does not stop it, stdlib.md 17.8."
    },
    {
      "code": "OS7019",
      "title": "A fill was reported with no price",
      "severity": "error",
      "stage": "host",
      "since": 1,
      "message": "The frame reports {qty} filled for intent {intent}, and no average fill price.",
      "placeholders": {
        "qty": "the cumulative filled quantity the frame reports",
        "intent": "the intent id the frame named"
      },
      "cause": "Step 3 of the fold takes the destination's own average over the cumulative quantity, because the engine never averages two averages of its own. A frame reporting more filled than the row holds and no price to take is a fill that can be marked against nothing: no position average, no realised profit, no equity point. It is refused whole rather than folded for its quantity alone, because a position holding a size and no price is worse than no position at all.",
      "fix": "Report the average fill price the destination computed over the cumulative quantity, on every frame that reports a quantity greater than the last one. A frame carrying no new quantity needs no price.",
      "autofix": false,
      "example": {
        "kind": "transcript",
        "before": "frame: intent 8, status filled, filled qty 3, average fill price absent",
        "after": "frame: intent 8, status filled, filled qty 3, average fill price 104.25"
      },
      "spec": "stdlib.md 17.8, 17.14",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. The fold refuses the frame and records the refusal as a word on the outcome it hands back, and a word is not a catalogue code, so a destination reporting a fill that can be marked against nothing is refused in silence. Raised when the outcome of a fold carries a code and a bar carries a channel for a diagnostic that does not stop it, stdlib.md 17.8."
    },
    {
      "code": "OS8001",
      "title": "A stateful call inside a branch",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "{name} advances only on the bars where this branch runs, and is absent on the rest.",
      "placeholders": {
        "name": "the stateful call, such as ema, rma or a user function holding var"
      },
      "cause": "A call site that does not execute on a bar leaves its series absent for that bar and its state untouched. The alternatives are worse: forcing the call would execute code the script said to skip, and carrying the previous value forward would draw a flat line that looks like data. This is almost always a mistake rather than an intent.",
      "fix": "Compute it unconditionally at the top level and use the result inside the branch.",
      "autofix": false,
      "example": {
        "before": "if trending\n    e = ema(close, 20)\n    plot(e, \"EMA\", aqua)",
        "after": "e = ema(close, 20)\nplot(trending ? e : none, \"EMA\", aqua)"
      },
      "spec": "language.md 11.4",
      "refines": null,
      "test": "tests/unit/check-conditional.test.ts"
    },
    {
      "code": "OS8002",
      "title": "A higher timeframe read with onUnconfirmed",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "This file sets onUnconfirmed = true and reads {timeframe}; together they repaint.",
      "placeholders": {
        "timeframe": "the requested interval"
      },
      "cause": "A higher timeframe bar is incomplete until it closes, and acting on an unconfirmed bar acts on that incomplete value. The chart then redraws when the higher bar closes, and the backtest and the live run disagree on the same data.",
      "fix": "Drop onUnconfirmed = true, or guard every use of the read with bar.isConfirmed.",
      "autofix": false,
      "example": {
        "before": "strategy(\"HTF\", onUnconfirmed = true)\nd = req.timeframe(\"1D\", high)\nif close > d\n    buy(qty = 1)",
        "after": "strategy(\"HTF\")\nd = req.timeframe(\"1D\", high)\nif close > d\n    buy(qty = 1)"
      },
      "spec": "language.md 7.5",
      "refines": null,
      "test": "tests/unit/check-repaint.test.ts"
    },
    {
      "code": "OS8003",
      "title": "No version declaration",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "This file declares no language version; it was compiled as version {version}.",
      "placeholders": {
        "version": "the newest language version the compiler implements"
      },
      "cause": "A file that names its version is parsed by that version's front end for ever, and every past front end is kept. A file without one is parsed by the newest, which is the one thing that can change under it.",
      "fix": "Add version {version} as the first line of the file.",
      "autofix": true,
      "example": {
        "before": "study(\"EMA cross\")",
        "after": "version 1\n\nstudy(\"EMA cross\")"
      },
      "spec": "language.md 4",
      "refines": null,
      "test": "tests/unit/diagnostics.test.ts"
    },
    {
      "code": "OS8004",
      "title": "A branch on an absent condition changes a value used later",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "{condition} can be absent, and this block assigns {name}, which is read at line {line}.",
      "placeholders": {
        "condition": "the condition expression as written",
        "name": "the name the block assigns",
        "line": "the line outside the block that reads it"
      },
      "cause": "An absent condition takes the false branch, so during warmup the block does not run and the name keeps whatever it held before. Warmup bars sit off the left edge of the screen, which is why this shape silently changes an answer and nobody notices.",
      "fix": "Decide what warmup means: test isNone({condition}) explicitly, or give {name} a starting value above the if.",
      "autofix": false,
      "example": {
        "before": "if rsi(close, 14) > 70\n    zone = \"high\"\nplot(zone == \"high\" ? 1 : 0, \"Zone\", aqua)",
        "after": "zone = \"mid\"\nif rsi(close, 14) > 70\n    zone = \"high\"\nplot(zone == \"high\" ? 1 : 0, \"Zone\", aqua)"
      },
      "spec": "language.md 6.6",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. The checker does not follow which names a branch on a possibly absent condition assigns, so the warmup shape this warns about compiles silently. Raised when the checker follows assignments out of a conditional block, language.md 6.6."
    },
    {
      "code": "OS8005",
      "title": "A lookahead read",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "This read uses {mode}, so the study shows values the bar it is drawn on could not have known.",
      "placeholders": {
        "mode": "the mode the read was given"
      },
      "cause": "A lookahead read takes a higher timeframe bar's final value on chart bars that fall before that bar closed. It is the strongest form of repainting there is, which is why it has to be written out in a word a reviewer sees on the line that causes it. The compiled study is also marked as repainting, so the host can say so.",
      "fix": "Drop the mode to take the default, which never repaints, unless the study is deliberately a study of what the higher bar went on to do.",
      "autofix": false,
      "example": {
        "before": "d = req.timeframe(\"1D\", high, mode = \"lookahead\")",
        "after": "d = req.timeframe(\"1D\", high)"
      },
      "spec": "language.md 7.5",
      "refines": null,
      "test": "tests/unit/check-repaint.test.ts"
    },
    {
      "code": "OS8006",
      "title": "A session average on a session-length bar",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "A session anchored average resets each session, and each bar of {interval} is a whole session, so it equals its source.",
      "placeholders": {
        "interval": "the chart's interval"
      },
      "cause": "The average is a within-session measure: it accumulates from the session's first bar. On a daily or longer interval each bar is its own session, so the accumulation is one bar long and the result is that bar's own price. The plot carries no information and the legend suggests it does.",
      "fix": "Use an intraday interval for a session anchored average, or plot the source directly and delete the call.",
      "autofix": false,
      "example": {
        "before": "plot(vwap(), \"Session average\", aqua)",
        "after": "plot(hlc3, \"Typical price\", aqua)"
      },
      "spec": "language.md 15.2",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. The checker does not compare a session average's call with the chart's interval, so the accumulation this warns about compiles silently. Raised when the checker reads the declared interval at the call site, language.md 15.2."
    },
    {
      "code": "OS8007",
      "title": "A plot sets the price pane's own formatting",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "{title} sets {option} while drawing over the price pane, which reformats the instrument's own axis.",
      "placeholders": {
        "title": "the plot's title, quoted",
        "option": "the option that was set, precision or format"
      },
      "cause": "precision and format on a plot apply to the price scale that plot maps to. Over the price pane that scale is the instrument's own, so the setting changes the axis every other series on that pane is read against, which is almost never what was meant.",
      "fix": "Set precision and format in the declaration, for the whole study, or drop them from a plot drawn over the price pane.",
      "autofix": false,
      "example": {
        "before": "study(\"Bands\", overlay = true)\nplot(upper, \"Upper\", aqua, precision = 0)",
        "after": "study(\"Bands\", overlay = true, precision = 0)\nplot(upper, \"Upper\", aqua)"
      },
      "spec": "language.md 13.2, 15.3",
      "refines": null,
      "test": "tests/unit/check-plot-options.test.ts"
    },
    {
      "code": "OS8008",
      "title": "An alert with no fixed id",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "This alert has no fixed id, so its identity is derived from its position at line {line}.",
      "placeholders": {
        "line": "the line the alert is declared on"
      },
      "cause": "A user's alert subscription is keyed by the alert's id, and an id derived from a call's position changes the moment a line is inserted above it. The subscription then belongs to an alert that no longer exists, and it stops firing without telling anybody. An id taken from an input() is not fixed either, and is derived in the same way: the key is written into the program before any setting is read, and a name that moves when somebody opens the settings dialog is not a name a subscription can be kept under.",
      "fix": "Give the alert a stable id of your own: alert(\"text\", id = \"emaCross\").",
      "autofix": false,
      "example": {
        "before": "if crossUp(fast, slow)\n    alert(\"EMA cross\")",
        "after": "if crossUp(fast, slow)\n    alert(\"EMA cross\", id = \"emaCross\")"
      },
      "spec": "language.md 15.3",
      "refines": null,
      "test": "tests/unit/check-repaint.test.ts"
    },
    {
      "code": "OS8009",
      "title": "This plot can never draw",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "{title} plots a value that is absent on every bar.",
      "placeholders": {
        "title": "the plot's title, quoted"
      },
      "cause": "A plot whose value is constantly none occupies a legend row, a settings group and an axis, and draws nothing. It is usually a placeholder that was left behind, or a name that was never assigned the value it was meant to hold.",
      "fix": "Plot the value that was meant, or delete the plot and its settings row.",
      "autofix": false,
      "example": {
        "before": "plot(none, \"Reserved\", aqua)",
        "after": "plot(ema(close, 20), \"EMA 20\", aqua)"
      },
      "spec": "language.md 6.7",
      "refines": null,
      "test": "tests/unit/check-warmup.test.ts"
    },
    {
      "code": "OS8010",
      "title": "A name is never read",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "{name} is assigned at line {line} and never read.",
      "placeholders": {
        "name": "the name that is never read",
        "line": "the line of its assignment"
      },
      "cause": "The statement still runs on every bar, so an unread name costs time on fifty thousand bars and tells the next reader that something depends on it. It is usually the remains of a calculation that was replaced. A name bound to a declaration handle is exempt: it is a compile-time binding with nothing left in the bar loop, and naming a fill or a level result and never reading it is legal (language.md 5.4).",
      "fix": "Use the value, or delete the line.",
      "autofix": false,
      "example": {
        "before": "slow = ema(close, 21)\nplot(ema(close, 9), \"Fast\", aqua)",
        "after": "plot(ema(close, 9), \"Fast\", aqua)"
      },
      "spec": "language.md 12.2",
      "refines": null,
      "test": "tests/unit/diagnostics.test.ts"
    },
    {
      "code": "OS8011",
      "title": "live var makes live and backtest differ",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "{name} is a live var, so it keeps its value across the updates of the moving bar.",
      "placeholders": {
        "name": "the name declared with live var"
      },
      "cause": "An ordinary var rolls back before each re-execution of the newest bar, which is what makes a live chart and a backtest of the same data agree. A live var opts out of that, so a script using one reports different numbers in the two places by design.",
      "fix": "Use var unless counting intrabar updates is the actual intent; keep live var only for that.",
      "autofix": false,
      "example": {
        "before": "live var barCount = 0\nbarCount = barCount + 1\nplot(barCount, \"Bars\", aqua)",
        "after": "var barCount = 0\nbarCount = barCount + 1\nplot(barCount, \"Bars\", aqua)"
      },
      "spec": "language.md 7.5, 8.2",
      "refines": null,
      "test": "tests/unit/check-handles.test.ts"
    },
    {
      "code": "OS8012",
      "title": "An ordered comparison against none is always absent",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "This {op} has none on one side, so it is absent on every bar.",
      "placeholders": {
        "op": "the comparison operator that was written"
      },
      "cause": "Ordered comparison propagates absence, so a comparison against none can only ever be none, and a condition of none takes the false branch. The branch is therefore dead. Equality is the operator that answers this question.",
      "fix": "Test absence with isNone(x), or with x == none, both of which are always true or false.",
      "autofix": false,
      "example": {
        "before": "if value > none\n    signal(\"READY\")",
        "after": "if not isNone(value)\n    signal(\"READY\")"
      },
      "spec": "language.md 6.4, 6.5",
      "refines": null,
      "test": "tests/unit/check-dead-code.test.ts"
    },
    {
      "code": "OS8013",
      "title": "Deprecated",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "{name} is deprecated since language version {version}; {replacement} does the same thing.",
      "placeholders": {
        "name": "the deprecated function or option",
        "version": "the language version that deprecated it",
        "replacement": "the name or option that replaces it"
      },
      "cause": "A construct that turns out to be a mistake is never removed and never changes meaning, because a saved script must keep working. It warns instead, and it will still be there in version 9.",
      "fix": "Replace {name} with {replacement}; the two compute the same values.",
      "autofix": true,
      "example": {
        "before": "plot(oldName(close, 14), \"Value\", aqua)",
        "after": "plot(newName(close, 14), \"Value\", aqua)"
      },
      "spec": "language.md 4.1",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. No name in the library is marked deprecated and there is no marker for one to carry, so the checker has nothing to warn about. Raised when the library carries a deprecation marker the checker reads, language.md 4.1."
    },
    {
      "code": "OS8014",
      "title": "A persistent value holds a bar index",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "{name} keeps a bar index across bars, and every index shifts when more history loads.",
      "placeholders": {
        "name": "the persistent name that holds bar.index"
      },
      "cause": "bar.index is a position in the data the engine was given, not an address. Loading more history renumbers every bar, so a stored index compared later is being compared against something that moved underneath it.",
      "fix": "Store time instead and compare timestamps; the bar's time does not move.",
      "autofix": false,
      "example": {
        "before": "var entryBar = none\nif enter\n    entryBar = bar.index",
        "after": "var entryTime = none\nif enter\n    entryTime = time"
      },
      "spec": "language.md 7.2",
      "refines": null,
      "test": null,
      "deferred": "Nothing raises this yet. The checker does not follow a bar index into a persistent value, so the stored position this warns about compiles silently. Raised when the checker follows a bar index into persistent state, language.md 7.2."
    },
    {
      "code": "OS8015",
      "title": "This loop never runs",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "The loop starts at {start}, ends at {end} and steps {step}, so the body never runs.",
      "placeholders": {
        "start": "the start value",
        "end": "the end value",
        "step": "the step value"
      },
      "cause": "A descending range with a positive step is empty, and so is an ascending range with a negative step: the loop does not silently reverse in either direction, because a form that reverses itself is the only shape of for loop that can spin for ever by accident.",
      "fix": "Add step -1 to count down, or swap the bounds to count up.",
      "autofix": false,
      "example": {
        "before": "for i = 9 to 0\n    total += close[i]",
        "after": "for i = 9 to 0 step -1\n    total += close[i]"
      },
      "spec": "language.md 10.3",
      "refines": null,
      "test": "tests/unit/check-dead-code.test.ts"
    },
    {
      "code": "OS8016",
      "title": "Unreachable code",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "Line {line} follows a return that always runs, so it never executes.",
      "placeholders": {
        "line": "the first unreachable line"
      },
      "cause": "A return exits the function immediately. Statements after one that always runs are dead, and the usual cause is an early exit that lost its if.",
      "fix": "Delete the unreachable lines, or move them above the return.",
      "autofix": false,
      "example": {
        "before": "fn pick(x) =>\n    return x\n    x * 2",
        "after": "fn pick(x) =>\n    x"
      },
      "spec": "language.md 11.3",
      "refines": null,
      "test": "tests/unit/check-dead-code.test.ts"
    },
    {
      "code": "OS8017",
      "title": "The condition is constant",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "This condition is {value} on every bar.",
      "placeholders": {
        "value": "true or false, whichever it folds to"
      },
      "cause": "A condition built only from literals and constant options has one answer for the whole run, so one branch is dead. It is usually a test that was pinned during debugging and left behind.",
      "fix": "Restore the test that was meant, or delete the branch that never runs.",
      "autofix": false,
      "example": {
        "before": "if true\n    signal(\"BUY\")",
        "after": "if crossUp(fast, slow)\n    signal(\"BUY\")"
      },
      "spec": "language.md 10.2",
      "refines": null,
      "test": "tests/unit/check-dead-code.test.ts"
    },
    {
      "code": "OS8018",
      "title": "An input is never used",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "The input {title} is declared at line {line} and never read.",
      "placeholders": {
        "title": "the input's title, quoted",
        "line": "the line it is declared on"
      },
      "cause": "The input still builds a row in the settings dialog, so a reader can change it and nothing happens, which is worse than the setting not being there at all.",
      "fix": "Use the name the input assigns, or delete the input() and its dialog row.",
      "autofix": false,
      "example": {
        "before": "len = input(20, \"Length\")\nplot(ema(close, 9), \"EMA\", aqua)",
        "after": "len = input(20, \"Length\")\nplot(ema(close, len), \"EMA\", aqua)"
      },
      "spec": "language.md 13.4",
      "refines": null,
      "test": "tests/unit/check-calls.test.ts"
    },
    {
      "code": "OS8019",
      "title": "A deleted object is still held",
      "severity": "warning",
      "stage": "check",
      "since": 1,
      "message": "{name} still holds the {kind} deleted at line {line}.",
      "placeholders": {
        "name": "the name or the array that refers to the deleted object",
        "kind": "the object kind: line, label, box or polyline",
        "line": "the line the delete is written on"
      },
      "cause": "An object lives until the script deletes it, and deleting it touches neither the name nor the array element that refers to it: there is no collection of unreachable objects, because unreachable and no longer wanted are different facts and only the script knows the second. What is left is stale rather than absent, so the next setter that reaches it stops the bar with OS4005, usually many bars after the line that caused it.",
      "fix": "Assign none to the name on the same path as the delete, and where the object came out of an array, remove the element as well as deleting the object.",
      "autofix": false,
      "example": {
        "before": "var zones: array<box> = []\npush(zones, draw.box(time, low, time, high))\nif size(zones) > 20\n    draw.delete(element(zones, 0))",
        "after": "var zones: array<box> = []\npush(zones, draw.box(time, low, time, high))\nif size(zones) > 20\n    draw.delete(element(zones, 0))\n    shift(zones)"
      },
      "spec": "language.md 5.4",
      "refines": null,
      "test": "tests/unit/check-deleted.test.ts"
    },
    {
      "code": "OS9001",
      "title": "Version not read by the importer",
      "severity": "error",
      "stage": "import",
      "since": 1,
      "message": "The importer reads scripts written for version 5 or 6 of the source dialect, and this one {found}.",
      "placeholders": {
        "found": "what the version annotation says instead: that it declares another version, naming it, or that it declares none"
      },
      "cause": "A script in the source dialect opens with an annotation comment naming the version of the dialect it is written for. The importer's reader, its table of built-ins and every rule it applies about where the two languages differ are written for versions 5 and 6, whose built-ins live in namespaces and whose declaration is an indicator or strategy call. An earlier version names its built-ins differently and differs in rules the importer does not model, so reading one under these rules would produce a translation that compiles and means something else. Nothing is translated: the result's source is empty and this is its only finding.",
      "fix": "Bring the script up to version 5 or 6 in the source dialect, or translate it by hand, and import it again.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=4\nstudy(\"Range\")\nplot(high - low)",
        "after": "version 1\n\nstudy(\"Range\")\nplot(high - low, \"Range\")"
      },
      "spec": "docs/writing/importing-a-script.md 2",
      "refines": null,
      "test": "tests/importer/refusals.test.ts"
    },
    {
      "code": "OS9002",
      "title": "Construct with no equivalent",
      "severity": "error",
      "stage": "import",
      "since": 1,
      "message": "The importer cannot translate {construct}, so the statement holding it was kept as a comment.",
      "placeholders": {
        "construct": "the form the importer met, named in a few words: a tuple assignment, an if used as a value, a comparison with na"
      },
      "cause": "Some forms of the source dialect have no OpenScript spelling that keeps their meaning: a value produced by an if or a switch, a tuple, a type, a method, an import, an array literal, a loop over a collection, and an equality test against na, which the source dialect answers false on every bar while OpenScript's own test for absence answers true where the value is absent. A few more are written in forms the importer's reader does not accept. The importer keeps the whole top level statement holding one as a comment line per source line, marked not translated, so the output still compiles and the original is there to translate from.",
      "fix": "Translate that statement by hand from the comment that holds it: the rest of the script was translated around it.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nindicator(\"Side\")\nside = if close > open\n    1\nelse\n    -1\nplot(side)",
        "after": "version 1\n\nstudy(\"Side\")\nside = close > open ? 1 : -1\nplot(side, \"Side\")"
      },
      "spec": "docs/writing/importing-a-script.md 4",
      "refines": null,
      "test": "tests/importer/refusals.test.ts"
    },
    {
      "code": "OS9003",
      "title": "Built-in with no mapping",
      "severity": "error",
      "stage": "import",
      "since": 1,
      "message": "{name} is not one of the built-ins the importer maps, so the statement holding it was kept as a comment.",
      "placeholders": {
        "name": "the built-in as the source writes it, namespace included"
      },
      "cause": "The importer translates a built-in only where it holds a row saying which OpenScript name computes the same thing and how the arguments line up. A built-in with no row, or a name the source never declares, is not guessed at: a function with a similar name can differ in its arguments, its warmup or its arithmetic, and a translation that compiled with the wrong one would draw a line that looks right and is not. The whole top level statement holding it is kept as a comment.",
      "fix": "Find the OpenScript library call that does the same job, check how it treats its first bars and absent values, and write the statement by hand.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nindicator(\"Range position\")\nrank = ta.percentrank(close, 20)\nplot(rank)",
        "after": "version 1\n\nstudy(\"Range position\")\nrank = percentRank(close, 20)\nplot(rank, \"Rank\")"
      },
      "spec": "docs/writing/importing-a-script.md 3",
      "refines": null,
      "test": "tests/importer/refusals.test.ts"
    },
    {
      "code": "OS9004",
      "title": "Declaration the importer cannot place",
      "severity": "error",
      "stage": "import",
      "since": 1,
      "message": "The importer writes the declaration from one indicator or strategy call at the top level, and this script {found}.",
      "placeholders": {
        "found": "what the importer found instead: that the script has none, that it declares a library, or that it makes a second declaration here"
      },
      "cause": "An OpenScript file carries exactly one declaration, and it is what makes the file a study or a strategy. The importer writes it from the source's indicator or strategy call and from nothing else, because a declaration it invented would decide whether the translation may place orders. A script with none, and a library, which has no declaration an OpenScript file can carry, are not translated at all: the result's source is empty and this is its only finding. A second declaration is kept as a comment and the first one is used.",
      "fix": "Give the source script exactly one indicator or strategy declaration at the top level, and import it again.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nbasis = ta.sma(close, 20)\nplot(basis)",
        "after": "version 1\n\nstudy(\"Basis\")\nbasis = sma(close, 20)\nplot(basis, \"Basis\")"
      },
      "spec": "docs/writing/importing-a-script.md 2",
      "refines": null,
      "test": "tests/importer/refusals.test.ts"
    },
    {
      "code": "OS9005",
      "title": "Reads a statement that was not translated",
      "severity": "error",
      "stage": "import",
      "since": 1,
      "message": "{name} is declared by the statement at line {line}, which was not translated, so this statement that reads it was kept as a comment too.",
      "placeholders": {
        "name": "the name, as the source writes it",
        "line": "the line of the statement that declares it and was kept as a comment"
      },
      "cause": "A statement that was not translated declares nothing in the output, so a later statement reading one of its names would not compile. Rather than hand back a file that fails, the importer keeps every such statement as a comment as well, in source order, so that one refusal is reported once at its cause and once at each statement that follows from it.",
      "fix": "Translate the statement at line {line} by hand first, then this one, which was kept as a comment only because it reads {name}.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nindicator(\"Rank\")\nrank = ta.percentrank(close, 20)\nsmooth = ta.sma(rank, 5)\nplot(smooth)",
        "after": "version 1\n\nstudy(\"Rank\")\nrank = percentRank(close, 20)\nsmooth = sma(rank, 5)\nplot(smooth, \"Smooth\")"
      },
      "spec": "docs/writing/importing-a-script.md 4",
      "refines": null,
      "test": "tests/importer/refusals.test.ts"
    },
    {
      "code": "OS9006",
      "title": "Argument with no equivalent",
      "severity": "error",
      "stage": "import",
      "since": 1,
      "message": "{argument} changes what {call} computes or trades, and OpenScript has no equivalent the importer can write.",
      "placeholders": {
        "argument": "the argument, as the source names it or by its position",
        "call": "the call it was given to, as the source writes it"
      },
      "cause": "Some arguments change the numbers a script produces or the orders it sends: a declaration's timeframe, a strategy's margin or its pyramiding above one, a limit price on an entry, a trailing exit, a quantity on a close, and a quantity on an entry in a strategy that sizes its orders in anything but units, which the source dialect counts in contracts and OpenScript in the declaration's own unit. Leaving one out would produce a translation that compiles and computes something else. An argument to the declaration or to an input is left out of that call, because the file needs its declaration and the rest of the script reads the input; every other call carrying one is kept as a comment.",
      "fix": "Translate the call by hand, deciding what OpenScript should do in place of {argument}, or remove {argument} from the source script if the script does not depend on it.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nindicator(\"Daily basis\", timeframe = \"D\")\nplot(ta.sma(close, 20))",
        "after": "version 1\n\nstudy(\"Daily basis\")\nplot(req.timeframe(\"1D\", sma(close, 20)), \"Basis\")"
      },
      "spec": "docs/writing/importing-a-script.md 4",
      "refines": null,
      "test": "tests/importer/arguments.test.ts"
    },
    {
      "code": "OS9007",
      "title": "Warmup and absent bars follow OpenScript",
      "severity": "warning",
      "stage": "import",
      "since": 1,
      "message": "{call} became {target} here and wherever else the script calls it, and {target} follows OpenScript's own warmup, arithmetic and handling of absent values, which the original is not guaranteed to share.",
      "placeholders": {
        "call": "the built-in as the source writes it",
        "target": "the OpenScript call it was translated to"
      },
      "cause": "OpenScript fixes, for every function, the first bar a value appears on, how a seeded average is seeded, the order its arithmetic is done in and what an absent value inside the window does (stdlib.md sections 2.4 and 20). The source dialect does not fix the same things to the same precision, and where it says anything it can say something else: it skips absent values in windows where OpenScript propagates them. So a translated average can be absent on a first bar where the original drew a value, or differ in the last digits. Over a source with no absent values, and after the first bars, the two compute the same quantity. The finding is given once per built-in, at its first call.",
      "fix": "Compare the first bars of the translation with the original, and where the script depends on them, write the value as an explicit recurrence held in var, seeded the way the original seeds it.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nindicator(\"Average\")\nplot(ta.ema(close, 20))",
        "after": "version 1\n\nstudy(\"Average\")\nplot(ema(close, 20), \"Average\")"
      },
      "spec": "language.md 6.7, 7.3; stdlib.md 2.4, 20.2",
      "refines": null,
      "test": "tests/importer/differences.test.ts"
    },
    {
      "code": "OS9008",
      "title": "Whole-number division in version 5",
      "severity": "warning",
      "stage": "import",
      "since": 1,
      "message": "Both sides of this division are whole-number constants, which version 5 of the source dialect divides without a fractional part, and OpenScript keeps the fraction.",
      "placeholders": {},
      "cause": "Version 5 of the source dialect gives the quotient of two whole-number constants as a whole number, and version 6 and OpenScript both keep the fraction (language.md 9.2). A constant here is a whole-number literal, or a name the script binds once to one and never reassigns. The importer writes the division as OpenScript writes it and says so, rather than deciding which of the two results the script's author was relying on.",
      "fix": "If the script relied on the whole-number result, wrap the translated division in trunc(); otherwise leave it as it is.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nindicator(\"Half\")\nhalf = 7 / 2\nplot(close * half)",
        "after": "version 1\n\nstudy(\"Half\")\nhalf = trunc(7 / 2)\nplot(close * half, \"Half\")"
      },
      "spec": "language.md 9.2",
      "refines": null,
      "test": "tests/importer/differences.test.ts"
    },
    {
      "code": "OS9009",
      "title": "Presentation argument left out",
      "severity": "warning",
      "stage": "import",
      "since": 1,
      "message": "{argument} changes how {call} is displayed or what it may allocate, not what it computes, and OpenScript has no equivalent, so the translation leaves it out.",
      "placeholders": {
        "argument": "the argument, as the source names it",
        "call": "the call it was given to, as the source writes it"
      },
      "cause": "Many arguments in the source dialect are about the picture rather than the numbers: a line that tracks the price, a label size, a legend entry, a count of drawings to keep, a style the OpenScript call does not offer. Leaving one out changes what the chart looks like and nothing the script computes or trades, so the call is translated and the argument is reported rather than silently dropped.",
      "fix": "Nothing needs to change unless the display mattered; where it did, restyle the translated call with the arguments OpenScript does have, such as its colour, width and style.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nindicator(\"Close\")\nplot(close, \"Close\", trackprice = true)",
        "after": "version 1\n\nstudy(\"Close\")\nplot(close, \"Close\")"
      },
      "spec": "docs/writing/importing-a-script.md 5",
      "refines": null,
      "test": "tests/importer/arguments.test.ts"
    },
    {
      "code": "OS9010",
      "title": "Order placed under OpenScript's order model",
      "severity": "warning",
      "stage": "import",
      "since": 1,
      "message": "{call} was translated into OpenScript's order calls here and wherever else the script uses it, and OpenScript decides when an order fills, how a reversal and a repeated entry are handled and when an exit level starts to apply by its own order model.",
      "placeholders": {
        "call": "the order call as the source writes it"
      },
      "cause": "The importer translates an entry into a close of any opposite position and an entry guarded so that it never adds to a position already held on its side, which is what the source dialect does with its default pyramiding, and an exit into a leg level guarded by the side of the entry it names, with profit and loss distances converted from ticks by the instrument's tick size. That is as close as the two order models come, and they are not the same model: an OpenScript exit sets the leg's level when it is called rather than when its entry fills, a repeated entry past the pyramiding limit is refused rather than ignored, and an order a script places while flat is sized and filled by the rules of stdlib.md section 17. The finding is given once per order call, at its first use.",
      "fix": "Backtest the translation beside the original and compare the two trade lists before relying on it, and adjust the order calls by hand where they part.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nstrategy(\"Cross\")\nfast = ta.sma(close, 10)\nslow = ta.sma(close, 30)\nif ta.crossover(fast, slow)\n    strategy.entry(\"Long\", strategy.long)",
        "after": "version 1\n\nstrategy(\"Cross\", capital = 1000000)\nfast = sma(close, 10)\nslow = sma(close, 30)\nif crossUp(fast, slow)\n    if pos.size < 0\n        close()\n    if pos.size <= 0\n        buy(tag = \"Long\")"
      },
      "spec": "stdlib.md 17.1, 17.2",
      "refines": null,
      "test": "tests/importer/orders.test.ts"
    },
    {
      "code": "OS9011",
      "title": "Equality over two absent values",
      "severity": "warning",
      "stage": "import",
      "since": 1,
      "message": "Both sides of {operator} can be absent on the same bar, and OpenScript counts two absent values as equal, which the original is not guaranteed to do.",
      "placeholders": {
        "operator": "the equality operator, == or !="
      },
      "cause": "OpenScript's equality is total: none == none is true and none != none is false, so that a test for absence can be written as a comparison (language.md 6.5). The source dialect does not count two absent values as equal. Where both sides of an equality can be absent together, which is every warmup bar of two averages, the translation and the original can take different branches on exactly those bars.",
      "fix": "If the original relied on two absent values never comparing equal, guard the translated comparison with isNone() on either side.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nindicator(\"Touch\")\nfast = ta.sma(close, 5)\nslow = ta.sma(close, 20)\nplot(fast == slow ? 1 : 0)",
        "after": "version 1\n\nstudy(\"Touch\")\nfast = sma(close, 5)\nslow = sma(close, 20)\nplot(not isNone(fast) and fast == slow ? 1 : 0, \"Touch\")"
      },
      "spec": "language.md 6.5",
      "refines": null,
      "test": "tests/importer/differences.test.ts"
    },
    {
      "code": "OS9012",
      "title": "The translation does not compile",
      "severity": "error",
      "stage": "import",
      "since": 1,
      "message": "The OpenScript compiler refused the translation of this statement with {code}, so the statement was kept as a comment.",
      "placeholders": {
        "code": "the catalogue code the compiler raised on the translated text"
      },
      "cause": "The importer compiles its own output before it returns it, so that what it hands back compiles. A statement can translate construct by construct and still be refused as a whole: version 5 of the source dialect lets a number stand where a condition is expected, and the source dialect lets a name inside a block keep a history and lets two values of different types meet where OpenScript refuses. The importer does not type the source script, so it learns of these from the compiler, keeps the statement as a comment and compiles again.",
      "fix": "Look up {code} in this catalogue and translate the statement by hand in the form that code's fix describes.",
      "autofix": false,
      "example": {
        "kind": "import",
        "before": "//@version=5\nindicator(\"Traded\")\ntraded = volume ? 1 : 0\nplot(traded)",
        "after": "version 1\n\nstudy(\"Traded\")\ntraded = volume > 0 ? 1 : 0\nplot(traded, \"Traded\")"
      },
      "spec": "docs/writing/importing-a-script.md 4",
      "refines": null,
      "test": "tests/importer/refusals.test.ts"
    }
  ]
}
