Documentation/Workflow canvas engine

Code data processing node

JavaScript or Python that computes new columns from the upstream data.

JavaScript or Python that computes new columns from the upstream data.

Where it sits in the pipeline

This node accepts one upstream connection and passes its output downstream. Connect it between the data source and the trading logic block.

Write JavaScript or Python that receives every upstream column as a plain array and returns new columns. The code really runs: JavaScript inside an in-process sandbox, Python through the local sidecar (`python/lattice_sidecar.py`, standard library only).

JavaScript

// input: { symbol, n, time[], open[], high[], low[], close[], volume[], ...upstream }
function compute(input) {
  const ret_1 = input.close.map((c, i) => (i ? c / input.close[i - 1] - 1 : NaN));
  return { ret_1, ma20: ta.sma(input.close, 20) };
}

Python

def compute(data):
    close = data['close']
    ret_1 = [NAN] + [close[i] / close[i - 1] - 1 for i in range(1, len(close))]
    return {'ret_1': ret_1, 'ma20': ta.sma(close, 20)}
  • Helpers: ta.sma / ema / std / roc / shift / rsi (JS also has ta.max / ta.min).
  • Every returned array must have exactly n values; use NaN for warm-up.
  • Returned columns are available to the strategy nodes and to code strategies via ctx.value(symbol, name).