T420
trade fields are read-only
Severity Error
The tr value of a trade handler describes a trade that already happened; its fields cannot be assigned.
Copy the value into a local (let adjusted = tr.size * 2.0) or into your own record and change that.
Failing example
script "Signed size"
data tape = subscribe(data.trades, minNotional: 100_000.0)
state net: float = 0.0
on tape.trade(tr) {
if !tr.isBuy {
tr.size = -tr.size
}
net += tr.size
}Fixed example
script "Signed size"
data tape = subscribe(data.trades, minNotional: 100_000.0)
state net: float = 0.0
on tape.trade(tr) {
let signed = tr.isBuy ? tr.size : -tr.size
net += signed
}