Docs / Rule language
Rule language
Rule language
A rule is a precise statement about a stock's own price history, such as C > H[-1] (closed above yesterday's high) or C > sma(C, 200) and rsi(C, 14) < 40. Ora evaluates it exactly on the latest completed session and answers with a belief: how decisively it is true.
- Send a rule as a yes_no question with
"ask"instead of"instructions", on a{"symbol": …}state. - The answer is a belief from 0.05 to 0.95: 0.50 exactly on the line, further from 0.50 the further past it, measured on that symbol's own normal scale.
- English questions about what is true now are compiled into the same language, and the answer shows the rule it ran.
- Rules and forecast questions mix freely in one request, and actions can fire on both.
Why a rule language
A forecast is a model's estimate of what happens next. Many trading decisions also need a fact about now: is it above the 200-day, did it gap, is this an inside day, is volume heavy. A model should not guess those; they can be computed. Ora computes them, in the same request as the forecasts, with no data to send.
| Exact | The rule runs on the symbol's daily bars (adjusted for splits) with the indicator definitions on these pages. Nothing is sampled or estimated. |
|---|---|
| Graded | A belief says how far past the line the reading is, so rsi(C, 14) > 70 with RSI at 71 and at 85 are different answers. A boolean cannot say that. |
| One grammar | Entries, exits, filters, scans, pattern checks and alert conditions are all written the same way, with and, or and not. |
| Explainable | Every rule answer carries the rule it evaluated, so a log of decisions is also a log of exactly what was checked. |
| Safe to type | A misspelled function is a 422 that names the nearest real one (Did you mean sma()?), never a rule that silently cannot fire. |
Send a rule
{
"model": "ora-fin1",
"state": {
"symbol": "NVDA"
},
"questions": {
"above_50d": {
"type": "yes_no",
"ask": "C > sma(C,50)"
}
}
}Open this in the Playground
The real answer for the session of 2026-10-30:
{
"model": "ora-fin1",
"answers": {
"above_50d": {
"type": "yes_no",
"yes_no": 0.0746,
"rule": "C > sma(C,50)",
"basis": "rule"
}
},
"usage": {
"input_tokens": 291,
"output_tokens": 4
},
"context": {
"source": "server",
"symbol": "NVDA",
"as_of": "2026-10-30"
},
"version": "ora-fin-0.1.1"
}
What a rule answer contains
| Field | |
|---|---|
yes_no | The belief, 0.05 to 0.95. See Operators and beliefs. |
rule | The rule that was evaluated: yours, or the one an English question was compiled to. |
basis | rule when you sent ask; comparison or pattern when an English question was compiled. |
explain | Compiled comparisons only: a short reading of the rule, such as today's close > sma200. |
An answer with no rule came from the forecast model. From English to rule shows which questions compile and which do not.
A tour in six rules
| Idea | Rule | Where |
|---|---|---|
| Closed above yesterday's high | C > H[-1] | Prices and offsets |
| 20-day closing breakout | C > highest(C, 20) | Windows |
| Trend plus momentum | C > sma(C, 200) and rsi(C, 14) > 50 | Operators and beliefs |
| Crossed above the 50-day today | crossup(C, sma(C, 50)) | Signals and events |
| Hammer at a 20-day low | hammer() and L <= 1.01 * lowest(L, 20) | Pattern functions |
| Volume twice the prior average | V > 2 * ref(avg(V, 20), -1) | Rule library |
In this section
- Grammar: what a rule may contain, precedence, literals.
- Operators and beliefs: how a comparison becomes a number, and what
and,or,notdo to it. - Prices and offsets, Windows, Indicators, Signals and events, Pattern functions: the building blocks, each with live beliefs.
- Function reference: every function on one page, with an example and its belief on four symbols.
- Rule library: 86 worked rules, from gaps to multi-condition setups.
- Common mistakes and Error messages: what goes wrong, and what the API says.
- Guides: the Rule playground series, and Write your own rule.
What rules cannot do (yet)
- Rules run on daily bars only: no intraday bars, no
@5mtimeframes, novwap()or opening range. - A rule reads one symbol's history. To compare a stock with an index, ask both and compare the answers in your code.
- Rules cannot read numbers you send in
state.context; they need a covered symbol. Earnings, dividends and splits facts are planned.
Rules in ask are question rules. The conditions that decide whether an action fires (drop5 >= 0.6) are a separate, simpler syntax: Rules and templates.
Information, not investment advice. Beliefs and probabilities on this page are real responses for the session shown and change with every session.