# Query syntax

> The full grammar of a strategy query: build modes, expression form, and the capability modules the parser understands.

Source: https://docs.texttoquant.com/reference/query-syntax

---

A query is more expressive than "indicator crosses value". This page is the reference for everything
the parser understands: the three ways to build a strategy, the expression form for comparisons the
flat syntax can't reach, and the capability modules you can stack in a single sentence.

## Build modes

You can author the same strategy three ways: they all compile to the same backtest, and you can
switch between them mid session.

| Mode | Best for |
| --- | --- |
| AI Assistant (natural language) | Fast drafts from one sentence |
| Visual builder | Precise condition trees, no syntax |
| AI copilot | Refining either mode by chat |

<Callout variant="info" title="Interchangeable">
  Switch modes at any time. The parsed strategy carries over both ways: a query reads back as a
  visual tree, and a visual tree reads back as text.
</Callout>

## Expression form

For comparisons the flat form can't express, rolling windows, N bars ago, multiples, or any
indicator used as an operand, write them inline:

| Building block | Example |
| --- | --- |
| Rolling window | `the 20-bar highest high`, `20-bar mean volume` |
| N bars ago | `RSI vs its value 5 bars ago` |
| Multiple | `volume above 2× its 20-bar average` |
| Aggregation | `highest`, `lowest`, `mean`, `sum`, `std` or `median` over a rolling window |
| Value when | `the RSI value the last time price crossed the 200 EMA` (value-when) |
| Indicator operand | `EMA of RSI`, `MACD histogram vs 0` |

The [operators reference](/docs/reference/operators#expression-form) is the canonical list; this
table mirrors it.

## Capability modules

Eleven building blocks the parser understands, mixable in a single query.

| Module | Example phrase |
| --- | --- |
| Divergence | `buy on bullish divergence on RSI`, `bearish OBV divergence`; see the [supported series](/docs/reference/operators) |
| [Performance gates](/docs/reference/entry-exit#performance-gates) | `only trade if performance is above 0%` |
| Multi timeframe | `when the daily RSI is above 50` |
| Stop plans | `move stop to break-even after 2% profit` |
| Time filters | `only on Mondays / NY session` |
| Risk guards | `wait at least 5 bars between trades` |
| Structure memory | `after price breaks and retests the level` |
| Pyramiding | `add on each new 10-day high up to 3 times` |
| ATR distance | `then price moves 2 ATR away` |
| Cross asset | `when BTC is also above its 200 EMA` |
| Volatility regime | `when ATR is in the bottom 10th percentile` |

### Sessions & filters

| Filter | Values |
| --- | --- |
| Sessions (UTC) | New York, London, Tokyo, Sydney |
| Calendar | weekdays, hour windows, blackout months |
| Risk guards | cooldown bars, max trades/day, consecutive loss circuit break, daily loss stop, drawdown circuit break |
| Structure refs | previous bar H/L, own previous, broken level, previous step |

<Callout variant="info" title="Stackable">
  Combine modules freely: a daily trend filter, a divergence entry, a break even stop, and
  Monday only, all in one sentence.
</Callout>

## Parsed attributes

Before you run, the parser exposes exactly what it extracted. Every field is editable in the UI.

| Field | Notes |
| --- | --- |
| asset / timeframe | Symbol + bar size |
| direction | long or short |
| market | spot vs futures |
| timeConstraint | relative or absolute dates |
| entryConditions | `AND`, `OR`, or [sequential](/docs/reference/operators#combining-conditions) (ordered with `then`) |
| exitConditions | OR, stops, targets |
| positionSizing | risk %, units, notional |

Next: browse the [indicator library](/docs/reference/indicators) or the
[operators](/docs/reference/operators) you compare with.
