Docs / Rule language
Rule language
Signals and events
A state is something that is true for a while (above the 50-day). An event happens on one bar (crossed above the 50-day today). Signal functions turn one into the other.
| Events answer 0.95 or 0.05 | crossup(C, sma(C, 50)) on its own is 1 or 0, with no margin to measure, so its belief is 0.95 on the day it happens and 0.05 every other day. The same holds for between() on its own. |
|---|---|
| Graded instead | If you want "how far above", compare: C > sma(C, 50). To require a recent cross and a margin, combine them: barssince(crossup(C, sma(C, 50))) <= 5 and C > sma(C, 50). |
| Ages | barssince(cond) is 0 on a bar where the condition holds and counts up after. It is unknown (0.50) until the condition has been true once. |
Signal functions
crossup(a, b)1 on the bar where a crosses above b (it was at or below b on the bar before), 0 otherwise. As a whole rule it answers 0.95 or 0.05.
crossup(C, sma(C, 50))Crossed above the 50-day today.crossdown(a, b)1 on the bar where a crosses below b.
crossdown(sma(C, 20), sma(C, 50))The 20-day crossed under the 50-day today.barssince(cond)Bars since a condition was last true (0 = true on this bar). Not known until it has been true once.
barssince(C > highest(C, 20)) > 30More than 30 sessions since the last 20-day closing breakout.Maths and logic helpers
abs(x)Absolute value.
abs(C / C[-1] - 1) > 0.02Moved more than 2% either way today.sqrt(x)Square root (negative input is not a number).
std(log(C / C[-1]), 20) * sqrt(252) > 0.4Annualized 20-day volatility above 40%.log(x)Natural logarithm (zero or negative input is not a number).
log(C / C[-20]) > 0.05A 20-session log return above 5%.sign(x)−1, 0 or 1.
sum(sign(C - C[-1]), 10) > 2More up days than down days over ten sessions, by at least three.iif(cond, a, b)a where the condition holds, b otherwise. Use it to switch a threshold by regime.
rsi(C, 14) < iif(C > sma(C, 200), 40, 30)Oversold, with a looser line (40) in an uptrend and a stricter one (30) below the 200-day.ref(x, -n)Any series n bars back: the offset for things that are not a price letter.
sma(C, 50) > ref(sma(C, 50), -10)The 50-day average is higher than ten sessions ago: rising.between(x, a, b)1 when x is inside [a, b] (inclusive, either order), else 0.
between(rsi(C, 14), 40, 60)RSI in the neutral band. As a whole rule it answers 0.95 or 0.05.least(a, b)The smaller of two series, bar by bar.
least(O, C) - L > 2 * abs(C - O)A long lower wick: twice the body.greatest(a, b)The larger of two series, bar by bar.
H - greatest(O, C) > 2 * abs(C - O)A long upper wick: twice the body.Recursion
rec(seed, step)A series built from its own previous value: inside step, self is the previous bar's result (seed before the first bar). Only arithmetic, comparisons and abs/sqrt/log/sign/iif/least/greatest/between may touch self.
C > rec(C, self + 0.1 * (C - self))Above a home-made exponential average (smoothing 0.1).Information, not investment advice. Beliefs and probabilities on this page are real responses for the session shown and change with every session.