Docs / Rule language
Rule language
Windows
A window function looks at the last n bars of any series: a price, an expression such as H - L, or another function. The one rule to remember is which windows include the current bar.
| Includes today | Excludes today |
|---|---|
sma avg mean sum min max std zscore median wma ema rma linreg highestbars lowestbars | highest lowest; percentrank ranks today against the n − 1 bars before it |
C > highest(C, 20) compares today with the 20 sessions before it, so it can be true. C > max(C, 20) compares today with a window that contains today, so at best the two sides tie. On XLE (2026-10-30), which closed at a 20-session high: breakout 0.6462, > max 0.5, >= max 0.5.
Warm-up
A window needs n bars before it has a value. Until then the comparison answers 0.50, never true: C > sma(C, 2000) is 0.5 on XLE because 2,000 sessions are more than the history loaded, while C > sma(C, 250) is 0.9463. A recent listing has the same effect on long windows.
Anything can go in a window
(H - L) > 2 * avg(H - L, 20) range against its own average sum(C > C[-1], 10) >= 6 count up days obv() > sma(obv(), 20) a function of a function std(log(C / C[-1]), 20) * sqrt(252) annualized volatility
Window functions
sma(x, n)Simple moving average of the last n bars, including the current one.
C > sma(C, 50)Above the 50-day average.avg(x, n)Another name for sma(). Same result.
V > avg(V, 20)Volume above its 20-day average.mean(x, n)A third name for sma().
C > mean(C, 100)Above the 100-day average.sum(x, n)Rolling sum of the last n bars. Summing a comparison counts the bars where it held.
sum(C > C[-1], 10) >= 6Up on at least six of the last ten sessions.min(x, n)Lowest value of the last n bars, INCLUDING the current one.
C < 1.02 * min(L, 20)Closed within 2% of the 20-day low. (L <= min(L, 20) would be a poor rule: min includes today, so the two sides are at best equal, and a tie answers 0.50.)max(x, n)Highest value of the last n bars, INCLUDING the current one. So C > max(C, n) can never be true.
C >= 0.98 * max(H, 20)Closed within 2% of the 20-day high.highest(x, n)Highest value of the n bars BEFORE the current one. This is the breakout form.
C > highest(C, 20)Closed above every close of the previous 20 sessions.lowest(x, n)Lowest value of the n bars before the current one.
C < lowest(C, 20)Closed below every close of the previous 20 sessions.std(x, n)Standard deviation over the window (population form, like most charting tools).
std(C, 10) < 0.5 * std(C, 50)Recent swings are less than half their longer-run size: compression.zscore(x, n)How many standard deviations the current value sits from its window mean. A flat window scores 0.
zscore(C, 20) < -2More than two deviations under the 20-day mean.median(x, n)Middle value of the window. Less pulled by one wild day than an average.
V > 2 * median(V, 20)Volume more than twice its typical (median) day.percentrank(x, n)Where the current value ranks among the n − 1 bars before it, 0 to 100.
percentrank(V, 50) > 90Volume in the top tenth of the last 50 sessions.wma(x, n)Linearly weighted moving average: recent bars count more.
wma(C, 10) > wma(C, 30)Fast weighted average above the slow one.ema(x, n)Exponential moving average, smoothing 2 / (n + 1).
C > ema(C, 21)Above the 21-day EMA.rma(x, n)Wilder's smoothing, 1 / n: what RSI and ATR are built from.
C > rma(C, 14)Above a Wilder-smoothed 14-day average.linreg(x, n)The least-squares line through the window, read at the current bar: a smoothed level, not the slope.
linreg(C, 20) > ref(linreg(C, 20), -5)The 20-day regression level is higher than a week ago: rising.roc(x, n)Percent change over n bars: roc(C, 20) = 5 means up 5% in 20 sessions.
roc(C, 20) > 5Up more than 5% over the last 20 sessions.cum(x)Running total from the first bar loaded.
cum(C > C[-1]) > cum(C < C[-1])More up days than down days across all the history loaded (about 1,500 sessions).highestbars(x, n)How many bars ago the window's high was set, 0 to n − 1 (0 = this bar). The window includes the current bar.
highestbars(H, 20) <= 3The 20-day high was set in the last four sessions.lowestbars(x, n)How many bars ago the window's low was set (0 = this bar).
lowestbars(L, 20) >= 15The 20-day low is at least 15 sessions old.Information, not investment advice. Beliefs and probabilities on this page are real responses for the session shown and change with every session.