Docs / Rule language
Rule language
Grammar
A rule is one expression. It is usually a comparison, or several joined with and and or. Everything below a comparison is arithmetic on whole price series.
rule := or
or := and ( "or" and )*
and := not ( "and" not )*
not := ( "not" | "!" ) not | compare
compare := sum ( (">" | ">=" | "<" | "<=" | "==" | "=" | "!=") sum )*
sum := product ( ("+" | "-") product )*
product := power ( ("*" | "/" | "%") power )*
power := unary ( "^" unary )*
unary := ("+" | "-") unary | primary
primary := "(" rule ")" | number | price [ "[" offset "]" ] | function "(" args ")"
price := O | H | L | C | V
offset := a whole number, e.g. -1 (yesterday)
Precedence, tightest first
| Level | Operators | Example |
|---|---|---|
| 1 | ( ), function calls, offsets | sma(C, 50), H[-1] |
| 2 | ^ power | (C / C[-1]) ^ 2 |
| 3 | * / % | 1.5 * avg(V, 20) |
| 4 | + - | sma(C, 20) + 2 * atr(14) |
| 5 | > >= < <= == = != | C > O |
| 6 | not (or !) | not C > sma(C, 50) |
| 7 | and | a and b |
| 8 | or | a or b |
and binds tighter than or, so a or b and c means a or (b and c). Use parentheses whenever you mix them; Combining conditions shows the difference on a real symbol.
Lexical rules
| Case | Keywords and function names are case-insensitive: AND, Sma(C, 50). Price letters are too: c is C. |
|---|---|
| Numbers | Plain decimals: 70, 1.5, .97. No exponents or thousands separators. Negative numbers work: willr(14) > -20. |
| Literals | true and false are 1 and 0. |
| Equality | = and == are the same. ! is the same as not. |
| Spaces | Ignored: C>H[-1] and C > H[-1] are one rule. |
| Offsets | Only on the five price letters: C[-1]. For anything else, ref(x, -n). |
| Names | A name that is not a price letter, a function or a keyword is read as a state field. Rules on Ora have no state fields yet, so rsi > 70 is a 422; write rsi(C, 14) > 70. |
| Truth inside arithmetic | A comparison is 1 or 0 inside a function or arithmetic, so sum(C > C[-1], 10) counts up days. Only the outermost comparisons, joined by and/or/not, become beliefs. |
Valid rules
C > H[-1] O < L[-1] * 0.99 and C > O (H - L) < lowest(H - L, 6) sum(C > C[-1], 10) >= 6 rsi(C, 14) < iif(C > sma(C, 200), 40, 30) crossup(macd(C), macdsignal(C)) hammer() and C > sma(C, 50)
Not valid
| Rule | Why | Write instead |
|---|---|---|
sma(C, 20)[-1] > 0 | Offsets go on price letters only | ref(sma(C, 20), -1) > 0 |
rsi > 70 | No state fields on Ora rules | rsi(C, 14) > 70 |
C > sma(C) | Windows need a period | C > sma(C, 50) |
C@5m > O@5m | Daily bars only | A daily rule |
The exact messages are on Error messages.
Information, not investment advice. Beliefs and probabilities on this page are real responses for the session shown and change with every session.
Create an account Open the Playground
Everything here also lives in the console, next to your keys and usage.