FlowscopeDocs

C001

setup collection is read-only

Severity Error

Arrays and maps created in setup (including literals such as [1.0, 2.0] and {"binance": 1.0}) are frozen once setup finishes. Calling push, set, remove, clear or assigning an element changes them, which is not allowed.

Keep the fixed data in setup, and declare a state collection for anything that changes while the script runs.

Failing example

Flowscope Script
script "Touched levels"
data chart = subscribe(data.ohlcv)
setup levels = [60_000.0, 65_000.0, 70_000.0]
on chart.close {
  let h = chart.high ?? 0.0
  let l = chart.low ?? 0.0
  if h >= 75_000.0 && l <= 75_000.0 {
    levels.push(75_000.0)
  }
}

Fixed example

Flowscope Script
script "Touched levels"
data chart = subscribe(data.ohlcv)
setup levels = [60_000.0, 65_000.0, 70_000.0]
state touched = float[](16)
on chart.close {
  let h = chart.high ?? 0.0
  let l = chart.low ?? 0.0
  for lvl in levels {
    if h >= lvl && l <= lvl && !touched.contains(lvl) && touched.len < 16 {
      touched.push(lvl)
    }
  }
}