SEQUENCE¶
SEQUENCE defines a deterministic multi-stage setup that advances on closed candles from one stream.
Use it when a trade needs ordered evidence, such as sweep -> reclaim -> momentum confirmation, before a rule can act.
STRATEGY sweep_reclaim VERSION 1
SYMBOLS
gold = BACKTEST:XAUUSD EVERY 1m
SEQUENCE sweep ON gold {
STAGE swept: gold.low < lag(lowest(gold.low, 20), 1)
STAGE reclaimed WITHIN 30m: gold.close > lag(lowest(gold.low, 20), 1)
STAGE go WITHIN 15m: rsi(gold.close, 14) > 50
}
RULES
WHEN SEQUENCE.sweep.complete
THEN BUY gold SIZING 1
Grammar¶
SEQUENCE <name> ON <stream> {
STAGE <stage_name> [WITHIN <duration>]: <condition>
STAGE <stage_name> [WITHIN <duration>]: <condition>
}
- A sequence has exactly one
ONstream. - A sequence must declare 2 to 8 stages.
- Stage names must be unique within the sequence.
WITHINis measured from the previous stage fire time.- A timeout resets the whole sequence, including snapshots.
Evaluation¶
Stages are edge-triggered and strictly ordered. A later stage being true early does not skip the current stage, and if it remains true after the previous stage fires, it must produce a fresh false-to-true edge before advancing.
Sequences run during the same closed-candle evaluation pass as rules:
- indicators, rolling snapshots, and aggregates update;
- matching sequences advance;
- rules evaluate;
SEQUENCE.<name>.completepulses are cleared after the rule pass.
No worker thread or async path is introduced. Backtest and live DSL strategies both use the same CandleHub close path.
Accessors¶
SEQUENCE.<name>.stage
SEQUENCE.<name>.complete
SEQUENCE.<name>.<stage>.price
SEQUENCE.<name>.<stage>.time
stageis numeric:0means idle,1..nmeans progress through the stage list.completeis a one-rule-pass boolean pulse when the final stage fires.<stage>.priceis theONstream close at the stage fire.<stage>.timeis theONstream candle close time in UTC epoch milliseconds.- Missing stage snapshots read as
0in numeric expressions.
Persistence¶
Sequence runtime state is persisted with strategy state: current stage, per-stage snapshots, prior edge values, and the complete pulse. A restart resumes the same progress instead of treating an in-flight setup as new.