Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS2302

error A history offset must be a whole number of 0 or more.

#What it means

The number inside [ ] after a series is how many bars back to look. It must be a whole number (int) of 0 or more.

#Typical cause

  • A negative offset such as close[-1]: future bars cannot be read.
  • A fractional or float offset such as close[1.5].

#How to fix it

Use a whole number of 0 or more. Convert a float with int(x). See Execution model.

#Example

ChartScriptError: CS2302
//@chartscript 1
indicator("Change")
plot(close - close[-1])

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Change")
plot(close - close[1])
  • CS5201 — A history offset cannot be negative or na (got offset).
  • CS5202 — name[...] reached offset bars back; raise max_bars_back to suggest in indicator().
  • CS3005 — max_bars_back must be between min and max.

The ChartScript documentation is in English for now; translations will follow.