MMTMMT Docs
Diagnostics

S009

state initializer calls a function that needs live data

S009

A state initializer calls a function that reads live data or state, or that has effects only a handler may have. Keep the helper free of such reads and effects, and do them inside a handler instead.

Failing example

script "example"
data chart = subscribe(data.ohlcv)
fn latest() -> float { return chart.close ?? 0.0 }
state value: float = latest()

Corrected example

script "fixed"
fn initial() -> float { return 0.0 }
state value: float = initial()

On this page