Messages and what fixes them
The builder shows one line and marks the row in the editor gutter. These are the messages you will meet, with the change that clears each one. The script is compiled and then run over one test bar as you type, so most mistakes are reported before the script ever reaches your chart. Where a message below starts with name, it names the call or the variable at fault.
Text and structure
| Message | Fix |
|---|---|
| Missing //@xfscript 1 header | Make //@xfscript 1 the first line of the script. |
| Empty script | The editor is empty. Paste the script. |
| Expected expression, found | A statement was split across lines, or an operand is missing. Put the whole call on one line. |
| Expected { | Move the opening brace onto the same line as the if condition or the function signature. |
| Expected ) after arguments | A closing parenthesis is missing, or a call was split across lines. |
| Expected variable name | A let or var needs a name, and a reserved word such as for, while or if cannot be one. |
| Expected = after variable name | A let or var needs = and an initial value. |
| Unterminated block | A closing brace is missing. |
| Unterminated string literal | A closing double quote is missing. |
| String literals cannot span lines | Use \n inside one quoted string instead of a real line break. |
| Unsupported escape | Only \n, \t, \" and \\ are supported. |
| Unexpected character | A character outside the language, such as a single quote, a backtick or a hash outside a string. |
| Unknown type name | Types are float, int, bool, string, color, side and void. |
| Expected to in for loop (for i = start to end) | Write for, the loop variable, =, the start, to, the end, and optionally by and a step. |
| break is only valid inside a loop | break and continue must sit inside the loop itself, not in a function called from it. |
| Expected : in conditional expression (condition ? a : b) | A ? needs its : and the second value. |
| Functions must be declared at top level | A fn cannot be declared inside another function. Move it to the top level. |
| Nested functions are not allowed | A fn cannot be declared inside an if branch. Move it to the top level. |
| Persistent var declarations must be at top level | var cannot be declared inside a function. Keep state in a top level var. |
| Series declarations must be top level | Move the let or var out of the if branch and assign inside it instead. |
| History access is only valid on a series identifier | Store the expression in a let first, then index that name. |
| return is only valid inside a function | Delete the return, or move it into a function body. |
| Only a function call can be used as a statement | A bare expression is not a statement. Assign it or call something. |
Names
| Message | Fix |
|---|---|
| Unknown function name | That name is not on this page. Check the spelling, or use a builtin that exists. |
| Unknown identifier name | The name was never declared. Declare it with let or var before use. |
| Unknown series name | History was read from a name that is not a series. |
| Duplicate or reserved name | Rename it. A global or builtin name cannot be reused. |
| Duplicate or reserved parameter name | A parameter repeats another, or reuses a series or global name. |
| Duplicate or reserved local name | A function local repeats a name already in use. |
| let series name is immutable | Declare it with var if you want to assign it with :=. |
| Assignment target name is not declared | Declare the var above the assignment. |
| User functions are pure and cannot assign state | Return a value from the function and assign it outside. |
| Recursive function cycle includes name | Remove the recursion. Recursion is rejected before the run. |
| Function locals are scalar and have no history | History indexing works on top level series only. |
| Loop locals are scalar and have no history | The same for a let inside a loop body. |
| Loop variable name is read-only | Copy it into a local, let j: float = i, and change the copy. |
| name cannot be a loop variable name | A loop variable cannot take a global, builtin or series name. Rename it. |
| Unknown identifier name; XF Script has ... | A Pine name. The message names the XFlow Script equivalent, such as time.day for dayofmonth. |
| Effort Zones output can only be used on the bar it describes | Use the Effort Zones value on the bar where you read it. |
| A script may declare indicator() at most once | Keep one indicator() call. |
Arguments and types
| Message | Fix |
|---|---|
| name expects N arguments, received M | Check the signature on this page. Optional arguments are shown in brackets. Argument counts of the builtins are checked before the script runs, including inside a branch that never executes. |
| name requires int, received nan | Annotate as float, or wrap with nz and math.round. |
| name requires type, received | The value does not match the annotation. Change the annotation or the value. |
| name expects a number, received | An argument is of the wrong type. Strings and numbers are never coerced. |
| name expects bool, received | A condition, an && or || operand, or a when argument is not a boolean. |
| name expects string, received | Text arguments must be strings. Format numbers with format.compact or format.fixed. |
| Expected #RRGGBB or #RRGGBBAA color, received | Colours are six or eight hex digits with a leading hash, and nothing else. |
| name style must be one of solid, dashed, dotted | One sentence covers every choice argument, and it lists what is accepted. |
| name shape must be one of x, circle, triangle, square, diamond | The same sentence for a marker shape. |
| name anchor must be one of above, below | The same for an anchor. |
| name fill mode must be one of none, bullish, bearish, bullish_close, bearish_close | The same for a zone fill mode. |
| plot.zone expects 3, 4, 7, or 8 arguments | Use the short form or the full event form, nothing between. |
| plot.zone start_offset must be an integer from -200000 through 0 | Move the left edge back by a whole number of bars. |
| plot.zone bars_right must be an integer from 0 through 200000 | Project right by a whole number of bars. |
| plot.box start_offset must be an integer from -200000 through 0 | The same rule for a box. |
| plot.box bars_right must be an integer from 0 through 200000 | The same rule for a box. |
| plot.segment bar_a and bar_b must be integer bar_index values | Pass bar_index values you stored, as whole numbers, never an offset or a time. |
| plot.text expects string text | Build the text with str.concat and the format builtins. |
| plot.label expects string text | The same for a readout line. |
| profile.fold bars_back must be an integer from 1 through 200000 | Fold a whole number of bars. |
| profile.fold value_area_percent must be finite | Pass a number such as 70. |
| profile.fold opacity must be between 0 and 1 | Opacity is a fraction, not a percent. |
| name index must be a non-negative integer or -1 | A row index is a whole number from 0 up, or -1 for none. A literal index below -1 is refused as you type. |
| tape.nth_largest_index rank must be a non-negative integer | Rank 0 is the largest print. |
| name depth must be a non-negative integer | A depth argument is a whole number. Omit it or pass 0 for every level. |
| format.fixed decimals must be an integer from 0 through 6 | Pass a whole number of decimals. |
| name keeps one value per bar and cannot be called inside a loop | Call it once per bar outside the loop and use its result inside. |
| name draws one value per bar and cannot be called inside a loop | Draw objects inside a loop, such as plot.marker, plot.box or plot.hbar, or move the call out. |
| name declares a setting and cannot be called inside a loop | Declare inputs at the top level. |
| for step must not be 0 | Use a positive or negative step. |
| plot.polygon edges must not cross; list the points in order around the shape | Order the points around the outline. |
| name bar offsets must be from -200000 through 500 | Keep plot.rect and plot.polygon positions inside the range. |
| plot.table row must be an integer from 0 through 19 | Rows are 0 to 19, columns 0 to 7. |
| profile.fold width_percent must be greater than 0 and at most 100 | Pass a percent, or nan for the chart look. |
| name timezone must be UTC, America/New_York, America/Chicago, Europe/Prague, Europe/London, Asia/Tokyo, Asia/Hong_Kong, Australia/Sydney, or a fixed offset in minutes | Name one of those zones, or pass whole minutes. |
| fn expects N arguments | A user function was called with the wrong number of arguments. |
| fn must return type | Every path through a non void function needs a return of that type. |
Inputs, sessions and bases
| Message | Fix |
|---|---|
| Inputs must be direct top-level variable initializers | Write let name = input.something(...) at the top level, on its own. |
| Input declarations require literal arguments | Every input argument must be a literal, not an expression. |
| Duplicate input key | Give every input its own key. |
| input.int key must match [A-Za-z][A-Za-z0-9_]{0,63} | Start the key with a letter and use letters, digits and underscore only. |
| input.int title must contain 1-80 characters | Shorten or fill in the title. |
| input.int min must not exceed max | Swap the bounds. |
| input.int step must be positive | Use a step above zero. |
| input.int values must be integers | Whole numbers only for input.int, including the step. |
| input.color default must be #RRGGBB or #RRGGBBAA | Write the default colour as a hex literal. |
| Session window must use HHMM-HHMM | Write the window as four digits, a hyphen and four digits, for example "0930-1600". |
| Unsupported session timezone | Use "UTC", "America/New_York", "Europe/Prague" or a whole number of minutes. |
| Session fixed offset must be an integer number of minutes | Pass whole minutes, such as -300. |
| Completed-session ranges require a daytime session window | session.open and session.adr need a window that starts before it ends. |
| indicator(name, base): the base must be a string literal | Write the base as a literal such as "cvd". |
| Unknown base study | Use one of the open bases listed on this page. |
| That study is protected and cannot be a base | Protected indicators cannot be extended. The message lists the open bases. |
| base.* reads the declared base study | Add the base to indicator("name", "base") before calling base.*. |
| base.series needs a literal series name | Write the series name as a literal. |
| base has no series | Use a series name the base publishes; the message lists them. |
Limits
| Message | Fix |
|---|---|
| Source exceeds 65536 bytes | Shorten the script. |
| Token count exceeds 20000 | Shorten the script. |
| AST node count exceeds 10000 | Shorten the script, or move repeated logic into a function. |
| Calls accept at most 24 arguments | Split a long str.concat into two. |
| Functions accept at most 16 parameters | Pass fewer values. |
| History offset must be an integer from 0 to 200000 | Use a whole number offset inside the range. |
| Plot count exceeds 64 | Reduce the number of distinct plot call sites. |
| Profile count exceeds 512 | Fold on a condition rather than on every bar. |
| Profile rows exceed 200000 | Fold fewer or shorter ranges. |
| plot.text accepts at most 8 lines | Reduce the number of \n breaks. |
| String exceeds 1024 characters | Shorten the text. |
| Statement count exceeds 10000 on one bar | The script does too much per bar. Simplify it. |
| Loop exceeded 100000 iterations on bar N | A loop runs too often on one bar, or a while condition never turns false. |
| Loops exceeded 25000000 steps in one run (stopped on bar N) | The loops do too much work over the whole window. Loop over fewer rows or fewer bars, for example only near last_bar. |
| Drawn objects exceed 250000 in one run | A loop draws too many objects. Filter inside the loop, or draw only on recent bars. |
| Strings built on one bar exceed 200000 | Build text once per bar, not once per pass of a loop. |
| mtf.* reads at most 8 different timeframes in one script | Use fewer different minutes values. |
| Call depth exceeds 32 | User functions call each other too deeply. |
| Series storage exceeds 8000000 cells | Declare fewer top level series. |
| Input data exceeds 1000000 market items | The chart holds more data than one run may read. Load a shorter range. |
| Aggregate work exceeds 1000000 items on one bar | One bar asked for too much whole bar work. Ask fewer distinct thresholds. |
| Script stopped after running longer than 8 seconds | One run took too long. The script does not run again until you edit it or change one of its settings. Do less work per bar. |
Protected indicators from other users
| Message | Fix |
|---|---|
| This indicator stopped on bar N (limit or runtime error) | The author's script stopped on the data of your chart. A protected script shows no more detail; try a shorter range, or ask the author. |
| Reload the page to run this indicator | A newer version is available. Reload the page. |
| This indicator is no longer available | The author deleted it, or it was removed from the gallery. |
