FlowscopeDocs

T407

handler on a snapshot source

Severity Error

data.book, data.volume and data.hl are snapshot sources: they do not emit events, they are queried. A handler such as on book.update therefore has nothing to react to.

Read the snapshot from a handler of a bar or trade subscription, for example on chart.update { let d = book.depth(0.5) }.

Failing example

Flowscope Script
script "Book imbalance"
data book = subscribe(data.book)
pane p = pane(title: "Imbalance", height: 0.2)
plot imb = plot.line(title: "Imbalance 0.5%", on: p)
on book.update {
  let d = book.depth(0.5)
  if d != null {
    imb.plot(d.imbalance)
  }
}

Fixed example

Flowscope Script
script "Book imbalance"
data (
  chart = subscribe(data.ohlcv)
  book = subscribe(data.book)
)
pane p = pane(title: "Imbalance", height: 0.2)
plot imb = plot.line(title: "Imbalance 0.5%", on: p)
on chart.update {
  let d = book.depth(0.5)
  if d != null {
    imb.plot(d.imbalance)
  }
}