FlowscopeDocs

T109

type is not indexable

Severity Error

[...] was applied to a value that has no index operation. Subscription fields with history (chart.close[3]), arrays, rolling buffers, maps and strings can be indexed; plain values such as a trade’s price, a context.* constant or a local number cannot.

If you need earlier values of something that has no history, push it into a rolling<T> buffer in state and index that.

Failing example

Flowscope Script
script "Trade acceleration"
data tape = subscribe(data.trades, minNotional: 50_000.0)
on tape.trade(tr) {
  if tr.size > tr.size[1] * 3.0 {
    log.info(str.format("size jump at {0}", tr.price))
  }
}

Fixed example

Flowscope Script
script "Trade acceleration"
data tape = subscribe(data.trades, minNotional: 50_000.0)
state sizes = rolling<float>(2)
on tape.trade(tr) {
  let prev = sizes.last()
  if prev != null && tr.size > prev * 3.0 {
    log.info(str.format("size jump at {0}", tr.price))
  }
  sizes.push(tr.size)
}