Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS3122

warning name changes on the chart bars (how), so a request cannot recompute it on the requested bars: there it is na (kw) or the chart’s current value. Compute it in a function called inside the request.

#What it means

This is a warning. Variables a request reads are normally recomputed on the requested bars. A variable declared with state, or one that is changed after its declaration, follows the chart's bars and cannot be recomputed there: the request sees na (for state) or the chart's current value.

#Typical cause

  • A counter or other state variable, or a reassigned let variable, used inside a request expression.

#How to fix it

Put the calculation in a function and call the function inside the request; it then runs on the requested bars with its own state. See Other timeframes and markets.

#Example

ChartScriptWarning: CS3122
//@chartscript 1
indicator("Daily up streak")
state streak: int = 0
streak = close > open ? streak + 1 : 0
plot(request.tf("1D", streak))

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Daily up streak")
function upStreak() {
    state n: int = 0
    n = close > open ? n + 1 : 0
    return n
}
plot(request.tf("1D", upStreak()))
  • CS3123 — name belongs to the code around this request; the request expression runs on other bars and reads it as na. Pass a market / timeframe instead, or compute the value inside the request.
  • CS3120 — Plots, inputs, drawings and alerts cannot be used inside a request expression.

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