Writing a strategy

The strategy spec — universe, indicators, entry and exit conditions, geometry — and what the DSL will and will not let you express.

A strategy is a spec — a structured, declarative description with no code in it. You can write that description in plain language and let the platform compile it, or edit the spec directly. Either way you confirm the interpreted spec before anything runs.

The five parts of a spec

  • Name — what the strategy is called.
  • Universe — the symbol or symbols, the timeframe, and the date range. Also the data source and cost class, which the platform fills in from the asset class.
  • Signals — the indicators the strategy uses, declared once by name, and the per-bar conditions for entering long or short, and optionally for exiting each side.
  • Geometry — the stop, the target, the position size, and optional rules that move the stop after entry. Considered separately from the entry: the same entry with a different stop is a different strategy.
  • Pre-registration — the floors the run is judged against, fixed before it starts.

Entry and exit conditions

A condition is a per-bar boolean expression over indicator outputs and bar fields (open, high, low, close, volume). The vocabulary is fixed: arithmetic and comparisons; and / or / not; crosses_above / crosses_below; “X for at least N bars”, “X within last N bars”, “bars since X between M and N”; and shift(series, N) for an N-bar-lagged value, with N forced to be zero or positive.

An exit condition closes an open trade on its side. It is checked at each bar’s close and filled at the next bar’s open, never at the close that triggered it. If an entry signal fires on that same bar, the next trade opens at that same open, so a stop-and-reverse system runs as described.

Deliberately absent: variable assignment, if/then/else, function definitions, loops, and indexing a specific past pivot by position. These all tend to encode sequential state, and a language that allows them cannot make the leak audit’s guarantee.

If you need a sequence, it is an indicator
Anything of the form “this pattern has completed as of this bar” lives in the library as a stateful indicator that emits a boolean series — divergences, structure breaks, candle patterns, higher-highs runs. The DSL stays declarative; the sequential logic sits behind a contract-checked component. See the indicator library.

Geometry

Stops can be a fixed distance, a multiple of ATR at entry, or read from a series (a swing level, with an optional buffer and a minimum distance). Targets are usually an R-multiple — a multiple of the actual stop distance — or a fixed distance, an ATR multiple, a structural level, or a value snapshotted at entry. Sizing is a fixed risk of N R per trade by default, where 1 R is the stop distance. An optional timeout force-closes a trade after N bars. A strategy can run without a target when a timeout, a trailing stop or an exit condition closes its winners.

Stop management moves the stop after entry: to breakeven (plus an optional offset) once the trade is N R in profit, and/or trailing it — a multiple of ATR behind the best price, along an indicator line, or up in fixed R steps. Each rule is checked at a bar’s close and applied from the next bar, a stop only ever tightens, and R is always measured from the original stop. A trade stopped out after a move is reported separately from an ordinary stop-out.

Pre-registration

Floors are either platform default— derived from the geometry’s implied chance baseline, the sample size, and standard significance thresholds — or user-committed, where you provide them explicitly (Pro and Research). Whichever you choose is recorded with the run and cannot be changed once it starts. See run history & trials.

The three test strategies the DSL is built to express — a trend-follower, a Bollinger-band mean-reversion with a structural stop, and one strategy built on a custom indicator — are the concrete guide to what fits. If a strategy needs something none of them do, the answer is a richer library, not a more permissive DSL.