Engine

Getting started with the engine

Prepare a small strategy experiment and understand what belongs in each editor.

Begin with one instrument, a short historical window, and one strategy you can explain. The SJS quickstart enters on an upward moving-average crossover and closes on a downward crossover, with no Pine or L3 dependency.

Prepare the experiment

Choose an instrument and available historical data, then record the interval, date range, and execution settings. Keep those settings fixed while changing the decision logic. A change in data or fill settings can change results independently of your source changes.

In Agent Lab, save a revision before comparing runs. In an app, use the existing historical test workflow described in Backtest, inspect, and launch.

Put code in the right place

SourceEntry pointUse it for
SJSThe strategy app functionRead context and request orders or closes
L3Named config, app, and intent exportsRun policy frames and gate execution requests
Pine ScriptPine sourceProduce calculations, signals, plots, or supported strategy orders

Put the main algorithm in SJS. The separate policy quickstart goes in the L3 source when you are ready to add advanced oversight. Its quantity guard waits for a strategy path to request an order; a run with no order requests will have no intent checks.

Know what the context contains

Your frame function receives context and the current bar. Session APIs such as context.getPositions() read runtime state; context.placeOrder(...) and context.closePositions(...) request execution. Optional helper functions and modules arrive through the frame arguments.

Use bar.date for strategy timing tied to historical data. Wall-clock time describes when your program is running, which is different from the time being replayed in a backtest.

Make the first run explainable

  1. Add the standalone crossover to SJS.
  2. Run it with a fixed instrument and one-minute historical inputs.
  3. Inspect its signal timestamps, warmup, and submission attempts.
  4. Compare flat, pending-order, and long-position behavior.
  5. Inspect orders and trades to distinguish permission, submission, and fills.

Once that behavior is clear, add optional L3 oversight and compare the same inputs with an execution gate enabled.

Continue with SJS or Execution flow.

On this page