FlowscopeDocs

S008

user function called in setup

Severity Error

User fns may read subscriptions, state and the strategy, so they only run inside handlers. A setup value, input default or declaration argument called one.

Write the expression directly in the setup value (setup-safe built-ins and the ternary operator are fine there), or compute the value in a handler and keep it in state.

Failing example

Flowscope Script
script "Tick offset"
data chart = subscribe(data.ohlcv)
fn ticks(n: float) -> float {
  return n * context.tickSize
}
setup offset = ticks(4.0)
plot above = plot.line(title: "High + 4 ticks")
on chart.close {
  above.plot(chart.high + offset)
}

Fixed example

Flowscope Script
script "Tick offset"
data chart = subscribe(data.ohlcv)
setup offset = 4.0 * context.tickSize
plot above = plot.line(title: "High + 4 ticks")
on chart.close {
  above.plot(chart.high + offset)
}