Runs once at the start of a model run. Use for setup, market search, or one-time data fetching.
Primary bar-by-bar lifecycle handler. Runs once per candle. Return OrderAction to place trades.
Optional intra-bar tick handler. Runs on each tick within a bar (if supported).
Runs at the end of a model run. Use for cleanup or final actions.
Get series reader. Use getSeries() for default, getSeries("alt") for multi-series strategies.
Timestamp (Date) for the current bar being processed.
Execution environment: "backtest" | "paper" | "live".
Current bar index (0-based) in the run.
Resolved market descriptor { id, provider, ticker?, symbol? }.
Current bar timeframe: "1m" | "5m" | "15m" | "1h" | "4h" | "1d" | "1w".
Resolved parameters from model definition. Typed based on parameters spec.
Structured logging. Message appears in backtest logs with optional metadata.
Dynamically switch the primary market and load its candles for the current run.
Number of bars available up to current index.
Get full OHLCV candle by offset. 0 = current bar, 1 = previous.
Get close price. series.close() = current, series.close(1) = previous bar.
Get open price for current or prior bar.
Get high price for current or prior bar.
Get low price for current or prior bar.
Get volume for current or prior bar.
Simple moving average over period bars.
Exponential moving average over period bars.
Highest high over period bars.
Lowest low over period bars.
Create buy order action. Return from onBar to execute. Supports limit price, tag, kind.
Create sell order action. Return from onBar to execute.
Exit the current position entirely.
Persist model state between bars. State survives across bar runs.
Current cash balance.
Cash plus position value (total equity).
Current position snapshot: size, avgPrice, unrealizedPnl, realizedPnl.
All order fills executed during the run.
Total fees paid during the run.
Fetch candle history for a market. Use in initialize or onBar for dynamic lookback.
Fetch price history series. Intervals: "1h" | "6h" | "1d" | "1w" | "max".
Search Polymarket events and markets. Use in initialize(). Requires apiBaseUrl for server backtests.
Identity helper for a full parameter map. Preserves TypeScript inference.
Integer parameter with optional min, max, step, unit.
Numeric parameter with optional min, max, step, unit.
Boolean on/off parameter.
String parameter with optional placeholder.
Enum parameter with a fixed option set.
Market selector parameter. Default: { id, provider }.