Expression Operators
1. Basic operators
Element-wise calculations performed independently at each data point
| Operator | Syntax | Description | Return type | Example |
|---|---|---|---|---|
| abs | abs(x) | Absolute value | Number | abs(close - open) |
| log | log(x) | Natural logarithm | Number | log(volume) |
| exp | exp(x) | Exponential function e^x | Number | exp(returns) |
| sqrt | sqrt(x) | Square root | Number | sqrt(variance) |
| sign | sign(x) | Sign function (returns -1, 0, or 1) | -1/0/1 | sign(returns) |
| round | round(x, decimals) | Rounds to the specified number of decimal places | Number | round(price, 2) |
| max | max(x, y) | Element-wise maximum | Number | max(open, close) |
| min | min(x, y) | Element-wise minimum | Number | min(open, close) |
| mean | mean([cols]) | Element-wise mean across multiple columns | Number | mean([open, high, low, close]) |
| if | if(cond, x, y) | Conditional selection | x or y | if(close > open, 1, -1) |
| clip | clip(x, lower, upper) | Clips values to [lower, upper] | Number | clip(returns, -0.1, 0.1) |
| qclip | qclip(x, q) | Symmetrically clips values to the [q, 1-q] quantiles | Number | qclip(returns, 0.01) |
2. Time-series operators
Rolling-window calculations over time, grouped by instrument
| Operator | Syntax | Description | Return type | Example |
|---|---|---|---|---|
| shift | shift(x, n) | Shifts by n periods (n > 0 retrieves historical values) | Number | shift(close, 1) |
| delta | delta(x, n) | n-period difference: x - shift(x, n) | Number | delta(close, 1) |
| pct | pct(x, n) | n-period rate of change: delta(x,n) / shift(x,n) | Number | pct(close, 1) |
| argmax | argmax(x, n) | Position of the maximum over n periods (1–n) | Integer | argmax(high, 20) |
| argmin | argmin(x, n) | Position of the minimum over n periods (1–n) | Integer | argmin(low, 20) |
| t_mean | t_mean(x, n) | n-period moving average | Number | t_mean(close, 20) |
| t_sum | t_sum(x, n) | n-period rolling sum | Number | t_sum(volume, 5) |
| t_max | t_max(x, n) | n-period maximum | Number | t_max(high, 20) |
| t_min | t_min(x, n) | n-period minimum | Number | t_min(low, 20) |
| t_std | t_std(x, n) | n-period standard deviation | Number | t_std(returns, 20) |
| t_var | t_var(x, n) | n-period variance | Number | t_var(returns, 20) |
| t_prod | t_prod(x, n) | n-period rolling product | Number | t_prod(1 + returns, 20) |
| t_median | t_median(x, n) | n-period median | Number | t_median(close, 20) |
| t_quantile | t_quantile(x, n, q) | q quantile over n periods | Number | t_quantile(close, 20, 0.75) |
| t_skew | t_skew(x, n) | n-period skewness | Number | t_skew(returns, 20) |
| t_kurt | t_kurt(x, n) | n-period kurtosis | Number | t_kurt(returns, 20) |
| t_rank | t_rank(x, n) | Rank within n periods (maximum = 1) | Integer | t_rank(close, 20) |
| t_pctrank | t_pctrank(x, n) | Percentile rank within n periods (0–1) | Number | t_pctrank(close, 20) |
| t_count | t_count(cond, n) | Number of periods for which the condition is true | Integer | t_count(close > open, 20) |
| t_all | t_all(cond, n) | Whether the condition is true for every period | Boolean | t_all(close > ma20, 5) |
| t_any | t_any(cond, n) | Whether the condition is true in any period | Boolean | t_any(volume > avg_vol * 2, 5) |
| t_corr | t_corr(x, y, n) | n-period rolling correlation | Number | t_corr(close, volume, 20) |
| t_cov | t_cov(x, y, n) | n-period rolling covariance | Number | t_cov(returns, market_returns, 60) |
| t_beta | t_beta(y, x, n) | n-period regression slope β | Number | t_beta(returns, market_returns, 60) |
| t_alpha | t_alpha(y, x, n) | n-period regression intercept α | Number | t_alpha(returns, market_returns, 60) |
| t_residual | t_residual(y, x, n) | n-period regression residual | Number | t_residual(returns, market_returns, 60) |
| t_zscore | t_zscore(x, n) | n-period time-series Z-score normalization | Number | t_zscore(close, 20) |
| t_scale | t_scale(x, n) | n-period time-series min-max normalization to [0,1] | Number | t_scale(rsi, 20) |
3. Cross-sectional operators
Calculations across all instruments, grouped by timestamp
| Operator | Syntax | Description | Return type | Example |
|---|---|---|---|---|
| c_mean | c_mean(x) | Cross-sectional mean | Number | c_mean(returns) |
| c_sum | c_sum(x) | Cross-sectional sum | Number | c_sum(volume) |
| c_max | c_max(x) | Cross-sectional maximum | Number | c_max(returns) |
| c_min | c_min(x) | Cross-sectional minimum | Number | c_min(returns) |
| c_std | c_std(x) | Cross-sectional standard deviation | Number | c_std(returns) |
| c_median | c_median(x) | Cross-sectional median | Number | c_median(pe_ratio) |
| c_rank | c_rank(x) | Cross-sectional rank (maximum = 1) | Integer | c_rank(returns) |
| c_pctrank | c_pctrank(x) | Cross-sectional percentile rank (0–1) | Number | c_pctrank(momentum) |
| c_percentile | c_percentile(x, q) | Cross-sectional quantile value | Number | c_percentile(volume, 0.9) |
| c_top | c_top(x, n) | Marks the top N values in the cross section | Boolean | c_top(momentum, 10) |
| c_bottom | c_bottom(x, n) | Marks the bottom N values in the cross section | Boolean | c_bottom(momentum, 10) |
| c_zscore | c_zscore(x) | Cross-sectional Z-score normalization | Number | c_zscore(pe_ratio) |
| c_scale | c_scale(x) | Cross-sectional min-max normalization to [0,1] | Number | c_scale(volume) |
| c_mad_zscore | c_mad_zscore(x) | Cross-sectional MAD Z-score (robust normalization) | Number | c_mad_zscore(returns) |
| c_clip | c_clip(x, lower, upper) | Clips values to a specified interval within the cross section | Number | c_clip(zscore, -3, 3) |
| c_qclip | c_qclip(x, q) | Quantile clipping within the cross section | Number | c_qclip(returns, 0.01) |
| c_residual | c_residual(y, x) | Cross-sectional regression residual (neutralization) | Number | c_residual(returns, market_cap) |
| c_absunit | c_absunit(x, a?) | Cross-sectional absolute-value normalization | Number | c_absunit(alpha) |
4. Technical indicators
Classic technical-analysis indicators calculated separately for each instrument
| Operator | Syntax | Description | Return type | Example |
|---|---|---|---|---|
| ta_ma | ta_ma(x, n) | Simple Moving Average (SMA) | Number | ta_ma(close, 20) |
| ta_ema | ta_ema(x, n) | Exponential Moving Average (EMA) | Number | ta_ema(close, 12) |
| ta_wma | ta_wma(x, n) | Weighted Moving Average (WMA) | Number | ta_wma(close, 20) |
| ta_rsi | ta_rsi(x, n) | Relative Strength Index (RSI) | 0-100 | ta_rsi(close, 14) |
| ta_roc | ta_roc(x, n) | Rate of Change (ROC) | Number | ta_roc(close, 10) |
| ta_mom | ta_mom(x, n) | Momentum | Number | ta_mom(close, 10) |
| ta_cci | ta_cci(high, low, close, n) | Commodity Channel Index (CCI) | Number | ta_cci(high, low, close, 20) |
| ta_willr | ta_willr(high, low, close, n) | Williams %R | Number | ta_willr(high, low, close, 14) |
| ta_mfi | ta_mfi(high, low, close, volume, n) | Money Flow Index (MFI) | 0-100 | ta_mfi(high, low, close, volume, 14) |
| ta_bias | ta_bias(x, n) | Bias ratio (BIAS) | Number | ta_bias(close, 20) |
| ta_ultimate | ta_ultimate(high, low, close, n1, n2, n3) | Ultimate Oscillator | Number | ta_ultimate(high, low, close, 7, 14, 28) |
| ta_atr | ta_atr(high, low, close, n) | Average True Range (ATR) | Number | ta_atr(high, low, close, 14) |
| ta_natr | ta_natr(high, low, close, n) | Normalized Average True Range (NATR) | Percentage | ta_natr(high, low, close, 14) |
| ta_bbands_upper | ta_bbands_upper(x, n, k?) | Upper Bollinger Band | Number | ta_bbands_upper(close, 20, 2) |
| ta_bbands_mid | ta_bbands_mid(x, n) | Middle Bollinger Band (the moving average) | Number | ta_bbands_mid(close, 20) |
| ta_bbands_lower | ta_bbands_lower(x, n, k?) | Lower Bollinger Band | Number | ta_bbands_lower(close, 20, 2) |
| ta_bbands_width | ta_bbands_width(x, n, k?) | Bollinger Band width | Number | ta_bbands_width(close, 20, 2) |
| ta_kc_upper | ta_kc_upper(high, low, close, n, k?) | Upper Keltner Channel | Number | ta_kc_upper(high, low, close, 20, 2) |
| ta_kc_lower | ta_kc_lower(high, low, close, n, k?) | Lower Keltner Channel | Number | ta_kc_lower(high, low, close, 20, 2) |
| ta_obv | ta_obv(close, volume) | On-Balance Volume (OBV) | Number | ta_obv(close, volume) |
| ta_cmf | ta_cmf(high, low, close, volume, n) | Chaikin Money Flow (CMF) | Number | ta_cmf(high, low, close, volume, 20) |
| ta_adosc | ta_adosc(high, low, close, volume, fast, slow) | Chaikin A/D Oscillator | Number | ta_adosc(high, low, close, volume, 3, 10) |
| ta_vwma | ta_vwma(close, volume, n) | Volume-Weighted Moving Average (VWMA) | Number | ta_vwma(close, volume, 20) |
| ta_adx | ta_adx(high, low, close, n) | Average Directional Index (ADX) | Number | ta_adx(high, low, close, 14) |
| ta_dmi_plus | ta_dmi_plus(high, low, close, n) | Positive Directional Indicator (+DI) | Number | ta_dmi_plus(high, low, close, 14) |
| ta_dmi_minus | ta_dmi_minus(high, low, close, n) | Negative Directional Indicator (-DI) | Number | ta_dmi_minus(high, low, close, 14) |
| ta_aroon_up | ta_aroon_up(high, low, n) | Aroon Up | Number | ta_aroon_up(high, low, 25) |
| ta_aroon_down | ta_aroon_down(high, low, n) | Aroon Down | Number | ta_aroon_down(high, low, 25) |
| ta_macd_dif | ta_macd_dif(x, fast, slow) | MACD DIF line (fast line minus slow line) | Number | ta_macd_dif(close, 12, 26) |
| ta_macd_dea | ta_macd_dea(x, fast, slow, signal) | MACD DEA line (EMA of DIF) | Number | ta_macd_dea(close, 12, 26, 9) |
| ta_macd_hist | ta_macd_hist(x, fast, slow, signal) | MACD histogram (DIF minus DEA) | Number | ta_macd_hist(close, 12, 26, 9) |
| ta_kdj_k | ta_kdj_k(high, low, close, n, k_smooth) | K line of the KDJ indicator | Number | ta_kdj_k(high, low, close, 9, 3) |
| ta_kdj_d | ta_kdj_d(high, low, close, n, k_smooth, d_smooth) | D line of the KDJ indicator | Number | ta_kdj_d(high, low, close, 9, 3, 3) |
| ta_kdj_j | ta_kdj_j(high, low, close, n, k_smooth, d_smooth) | J line of the KDJ indicator | Number | ta_kdj_j(high, low, close, 9, 3, 3) |
| ta_stoch_k | ta_stoch_k(high, low, close, n) | Stochastic %K line | Number | ta_stoch_k(high, low, close, 14) |
| ta_stoch_d | ta_stoch_d(high, low, close, n, d_smooth) | Stochastic %D line | Number | ta_stoch_d(high, low, close, 14, 3) |
| ta_cross_over | ta_cross_over(x, y) | Crossover signal (x crosses y from below) | Boolean | ta_cross_over(ma5, ma20) |
| ta_cross_under | ta_cross_under(x, y) | Crossunder signal (x crosses y from above) | Boolean | ta_cross_under(ma5, ma20) |
| ta_breakout_high | ta_breakout_high(high, n) | Signal when price breaks above the N-period high | Boolean | ta_breakout_high(high, 20) |
| ta_breakout_low | ta_breakout_low(low, n) | Signal when price breaks below the N-period low | Boolean | ta_breakout_low(low, 20) |
5. Candlestick patterns
Recognition of classic candlestick patterns
| Operator | Syntax | Description | Return type | Example |
|---|---|---|---|---|
| ta_marubozu_bull | ta_marubozu_bull(open, close, high, low) | Bullish marubozu | Boolean | ta_marubozu_bull(open, close, high, low) |
| ta_marubozu_bear | ta_marubozu_bear(open, close, high, low) | Bearish marubozu | Boolean | ta_marubozu_bear(open, close, high, low) |
| ta_doji | ta_doji(open, close, high, low) | Doji | Boolean | ta_doji(open, close, high, low) |
| ta_pin_bar_long | ta_pin_bar_long(open, close, high, low) | Bullish pin bar (long lower wick) | Boolean | ta_pin_bar_long(open, close, high, low) |
| ta_pin_bar_short | ta_pin_bar_short(open, close, high, low) | Bearish pin bar (long upper wick) | Boolean | ta_pin_bar_short(open, close, high, low) |
| ta_inside_bar_bull | ta_inside_bar_bull(high, low, close) | Bullish inside bar | Boolean | ta_inside_bar_bull(high, low, close) |
| ta_inside_bar_bear | ta_inside_bar_bear(high, low, close) | Bearish inside bar | Boolean | ta_inside_bar_bear(high, low, close) |
| ta_engulfing_bull | ta_engulfing_bull(open, close) | Bullish engulfing pattern | Boolean | ta_engulfing_bull(open, close) |
| ta_engulfing_bear | ta_engulfing_bear(open, close) | Bearish engulfing pattern | Boolean | ta_engulfing_bear(open, close) |
| ta_three_rising | ta_three_rising(close) | Three consecutive rising closes | Boolean | ta_three_rising(close) |
| ta_three_falling | ta_three_falling(close) | Three consecutive falling closes | Boolean | ta_three_falling(close) |
| ta_hammer | ta_hammer(open, close, high, low) | Hammer | Boolean | ta_hammer(open, close, high, low) |
| ta_shooting_star | ta_shooting_star(open, close, high, low) | Shooting star | Boolean | ta_shooting_star(open, close, high, low) |
| ta_morning_star | ta_morning_star(open, close, high, low) | Morning star | Boolean | ta_morning_star(open, close, high, low) |
| ta_evening_star | ta_evening_star(open, close, high, low) | Evening star | Boolean | ta_evening_star(open, close, high, low) |
| ta_top_divergence | ta_top_divergence(price, indicator, n) | Bearish divergence signal | Boolean | ta_top_divergence(close, rsi, 20) |
| ta_bottom_divergence | ta_bottom_divergence(price, indicator, n) | Bullish divergence signal | Boolean | ta_bottom_divergence(close, rsi, 20) |