Write a condition over price bars. It is tested on every bar; bars where it is
true become signals. Use it for entries like C > avg(C,20).
Price variables & offsets
O H L C V |
Open, High, Low, Close, Volume of the current bar. |
C[-1], O[-2] |
Prior bars. C[-1] = yesterday's close. Offsets are negative into the past. |
For min max sum avg mean average, the second argument decides the meaning:
- A plain number → rolling window (bar count).
min(C,20)= lowest close of the last 20 bars. - Anything else (a variable/expression) → element-wise, like Excel.
min(C,O)= the smaller of close and open on that bar.
So max(H,10) is a 10-bar high, but max(C,O) is the candle body top.
With 3+ args they are always element-wise: max(H,C,O).
Windowed aggregates — 2nd arg is a bar count
sum avg mean min max | Running total, average, min, max over N bars. |
stdev stdevp var varp | Sample / population std-dev and variance over N bars. |
median count | median(C,20); count(x,N) = number of valid bars. |
percentile(x,N,p) | p in 0–1. percentile(C,60,0.9) = 90th pct of last 60 closes. |
quartile(x,N,q) | q in 0–4 (0=min, 2=median, 4=max). |
large(x,N,k) small(x,N,k) | k-th largest / smallest in the window. large(C,20,1) = 20-bar high. |
Math — element-wise
abs sign sqrt exp ln log(x[,base=10]) log10 power(x,y) mod(x,y)
int trunc(x[,d]) round(x[,d]) roundup(x[,d]) rounddown(x[,d]) ceiling(x[,sig]) floor(x[,sig]).
round is half-away-from-zero; mod takes the sign of the divisor (Excel-style).
Logic & comparisons
and or not > >= < <= == != = | Combine and compare. = and == are the same. |
if(c,a[,b]) | a when c is true, else b (0 if omitted). |
ifs(c1,v1,c2,v2,...) | First true condition wins. |
switch(x,v1,r1,...[,def]) | Match x against values; optional default. |
between(x,a,b) least(a,b) greatest(a,b) ref(x,n) | Range test, 2-arg min/max, and offset lookup. |
Errors & missing data
Division by zero, sqrt of a negative, ln of ≤0, and not-enough-history all produce a
blank (NaN) — that bar simply doesn't fire. Trap it with
iferror(x,alt) / ifna(x,alt), or test with
iserror(x) / isna(x). Example:
iferror((C-C[-5])/C[-5]*100, 0) > 5.
Calendar — zero-arg, current bar's date
month() year() dom() dow() quarter() week() doy() —
e.g. month() == 12 fires on December bars.
C > avg(C,20) + 2*stdev(C,20)Bollinger upper break(C - avg(C,20)) / stdev(C,20) > 2z-score overboughtC >= percentile(C,60,0.9)top-decile close(min(C,O) - L) > 0.6*(H - L) and C >= Ohammer (element-wise min)if(C>O, V, 0) > 1.5*avg(V,20)up-day volume thrust