EngineSQL-Inspired Rules / SQX

Working with SJS

Keep decision ownership clear across SJS and compiled SQX rules.

SJS is the main algorithm path for custom calculations, state, entries, and exits. SQX can supply small declarative rules and configured primitives alongside it. Policies remain an advanced L3 capability; SQX does not add policies to the SJS module scope.

Frame order matters

The shared runner invokes the L3 frame hook, then SJS, then the applicable configured L2/L1 branch, then native Pine. A SQX rule running after SJS cannot prevent or undo a request SJS already sent.

The position-versus-tick branch is chosen using the matching-position snapshot captured before the hooks. An order or close during SJS does not guarantee the branch switches immediately within that same invocation.

Use SJS to validate evidence before its own request. Use execution controls and the L3 intent gate where appropriate for checks shared across request paths.

Decide who owns the action

ArrangementResponsibility
SJS owns executionSQX/configured models provide only the intended supporting behavior; avoid also enabling an order primitive for the same event
SQX owns a primitive actionConfigure its baseline, conditions, and execution settings explicitly
SJS controls later branchesUse its documented skip() / skipall() helpers intentionally

SJS skip() affects later ordinary L2 work; skipall() also affects L1. These helpers do not automatically return from the SJS function. Explicitly return if your script should stop its own remaining statements.

Configuration and saved state

App-form SQX edits compile declarations into L1 models and rules into multi L2 models. This can replace model configuration managed by those fields; avoid independently editing two competing representations without checking the saved app.

Agent Lab compiles non-empty SQX into its run's model configuration. When SQX is empty it uses the draft's model arrays. Keep source, configuration, and the tested revision together when comparing runs.

Move complex decisions into SJS

Use SJS for OR or nested branching, finite-value validation, cooldowns, crossing detection, event consumption, and broker/order reconciliation. Keep the rule source small enough that each line has an explainable role.

Continue with examples.

On this page