> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xarchive.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Diagnostics

> Every code the script editor reports, what it means and what to do.

Each problem the script editor reports has a code. A code never changes meaning, so a person or an agent can act on it. Codes from the Pine translation start with `PN`; see [Pine Script](/terminal/guides/pine).

## Writing the script

Found when the script is checked, before it runs.

### OX1000

**The source does not parse.**

Fix the syntax at the line shown.

### OX1001

**The script must start with indicator(...).**

Make `indicator(name, options)` the first statement.

### OX1002

**This statement cannot run at the top level.**

The top level may hold only indicator(), const declarations, plot.level(), function declarations and handler registrations. Move logic into a handler such as `chart.onBar(() => { ... })`.

### OX1003

**Top-level let and var are not allowed.**

Persistent values are declared state: use `const x = state.bar(0)` and write `x.value` in a handler.

### OX1004

**A top-level collection is changed after setup.**

Top-level arrays, objects, Maps and Sets are constants. Use `state.list(n)` or `state.map(n)` for data that changes.

### OX1006

**indicator(...) may be called only once, at the top level.**

Keep one `indicator(...)` call, as the first statement.

### OX1010

**Scripts have no imports or exports.**

A script is one file. Everything it can use is a global of the script API.

### OX1011

**eval and the Function constructor are not available.**

Write the code directly.

### OX1012

**The with statement is not allowed.**

Name the object explicitly.

### OX1013

**async and await are not available.**

Handlers run synchronously per bar or event; data arrives through streams.

### OX1014

**Generators are not available.**

Use a loop or an array.

### OX1015

**Classes are not available.**

Use plain objects and functions; persistent values are declared state.

### OX1016

**`this` is not available at the top level.**

Name the value you mean.

### OX1017

**finally blocks are not allowed.**

A finally block can swallow the step limit. Use try/catch without finally.

### OX1018

**debugger statements are not allowed.**

Use `log.info(...)` to inspect values.

### OX1019

**This TypeScript construct is not supported.**

Scripts use erasable TypeScript only: no enum, namespace, decorators or parameter properties. Use a union of string literals instead of an enum.

### OX1020

**This global is not available in scripts.**

Scripts see only the script API and plain JavaScript values (Math, Number, String, Array, Object, JSON, Map, Set).

### OX1021

**Math.random is not available.**

Use `random(seed)`, which gives the same numbers everywhere.

### OX1022

**constructor, prototype and **proto** are not accessible.**

Work with the values directly.

### OX1023

**Globals and API objects cannot be assigned to.**

Declare your own value, or write a state cell’s `.value`.

### OX1024

\*\***= works on a plain variable only.**

Write `a.b = a.b ** c`.

### OX1025

**Names starting with \_\_ are reserved for the engine.**

Rename the variable.

### OX1101

**This constructor can be called only at the top level (setup).**

Create inputs, streams, state, indicators, plots and alerts once at the top level; update them in handlers.

### OX1103

**Handlers must be registered at the top level, unconditionally.**

Write `stream.onBar(...)` as its own top-level statement.

### OX1104

**API objects cannot be indexed dynamically.**

Name the member: `chart.close`, or read a bar value by name with `chart.source(name)`.

### OX1105

**This state is updated from two streams’ handlers.**

Each state object, series and indicator belongs to one stream. Give each stream its own, and read the other stream’s value instead of writing it.

### OX1106

**Event handlers may change only tallies and live state.**

Events are never replayed, so they cannot change state that rolls back. Add to a `tally()` or `tallyBy(n)`, or use `state.live(...)`, and use the result in the chart’s onBar.

### OX1107

**Tallies are filled by event handlers.**

Call `tally.add(...)` in `trades.onTrade` or `liquidations.onLiquidation`. In a bar handler, use a local or `state.bar(...)`.

### OX1108

**Plots, markers and drawings are set from the chart’s handlers.**

Set them in the onBar or onClose of the chart’s own `bars()` stream, reading the other stream there.

### OX1109

**This stream has no such handler.**

Bar streams have onBar and onClose, trades() has onTrade, liquidations() has onLiquidation. Sample streams have no handlers: read them in a bar handler.

### OX1110

**A handler must be a function.**

Pass an arrow function, or the name of a top-level function.

### OX1901

**This indicator is updated inside a condition.** (warning)

An indicator advances only when update runs, so it skips the bars where the condition is false (Pine’s call-site rule). Update it on every bar and use the value conditionally, unless that is what you mean.

## Running the script

Found while the script runs: a limit, a value out of range, a call in the wrong place.

### OX2001

**A constructor was called inside a handler.**

Create it once at the top level and update it in the handler.

### OX2002

**This can be called only inside a handler.**

Indicators update and handlers register at the times docs/scripting.md §2 sets out.

### OX2003

**This state cell holds numbers.**

Its initial value was a number. Declare `state.bar<number | null>(null)` or similar for a cell that can hold other values.

### OX2004

**A state list, map or tally is full.**

Raise its capacity (up to the limit) or remove old entries.

### OX2005

**A size is over the limit.**

Series keep at most 5,000 bars, tallyBy 10,000 keys, lists and maps 100,000 entries, drawings 500 per kind.

### OX2006

**A series was read further back than its lookback.**

Declare a larger lookback: `series(n)`.

### OX2007

**More than 64 plots.**

Combine plots, or split the script.

### OX2008

**An input is declared wrongly.**

Check the default value and the options.

### OX2009

**Plots, markers and drawings can be set only from the chart’s handlers.**

Set them in the chart stream’s onBar or onClose.

### OX2010

**An argument is not valid.**

Check the value named in the message.

### OX2011

**Unknown time zone.**

Use an IANA name such as `America/New_York`, or `UTC`.

### OX2012

**More than 9 tables.**

Reuse a table: clear it and write new cells.

### OX2013

**A list index is out of range, or the list is empty.**

Check `list.length` first.

### OX2100

**The script threw an error.**

Read the message and the line.

### OX2105

**This state is updated from two streams’ handlers.**

Each state object, series and indicator belongs to the stream whose handler first updated it.

### OX2106

**An event handler changed state that rolls back.**

Event handlers may change only tallies and live state.

### OX2107

**A tally was added to outside an event handler.**

Fill tallies in onTrade or onLiquidation.

### OX2200

**The step limit ran out.**

A script gets 10 million steps (loop iterations and function calls) for setup, per batch of 512 bars and per live update. Look for a loop that does not end, or work that can move out of the loop.

## The engine's own failures

Never the script's fault. Simplifying what the message names may get past one.

### OX9001

**The engine failed on this script, which is our bug, not yours.**

Please report the script. Simplifying what the message names (a very deeply nested expression, say) may get past it meanwhile.

### OX9002

**The engine could not read the data this script reads, which is our bug, not yours.**

Please report it. Reloading the page starts the data over.

## Next step

Back to the [reference](/terminal/reference).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.