Widget Builder Language
Learn the command language for creating custom watchlists, real-time filters, and reusable macros in the Widget Builder.
The Widget Builder uses a domain-specific language (DSL) for filtering and analyzing stock market data. You can filter symbols based on technical and fundamental criteria, access historical bar data with time ranges, apply aggregation methods, and define reusable macros.
Open the Widget Builder by typing W in the command terminal.
Commands
The language has three commands: query, ticker, and macro.
query
Scans symbols against filter criteria and returns matching results. Use this to screen stocks.
query [symbols] [where <filter>] [sorton <field> [asc|desc]]
[display <fields>] [extract [asc|desc|split] <count>] [as "name"]
| Clause | Description | Example |
|---|---|---|
symbols | Symbol list to scan (defaults to all) | AAPL, MSFT or W..mylist |
where | Filter condition | where Volume[0] > 1000000 |
sorton | Sort results by field | sorton Volume desc |
display | Custom columns to show | display Close[0..19].Average as "SMA20" |
extract | Limit results | extract desc 10 (top 10) |
as | Name the query | as "High Volume Gainers" |
Example — find the top 20 stocks above their 50-day moving average with 2x relative volume:
query where Close[0] > Close[0..49].Average & Volume[0] > AvgVolume * 2
display Close[0..19].Average as "SMA20", Volume[0] / AvgVolume as "RelVol"
extract desc 20
ticker
Creates a real-time widget that evaluates filter rules on every trade or quote update.
ticker <symbols> <filter> [reasons] [display <fields>]
| Clause | Description | Example |
|---|---|---|
symbols | Symbols to monitor | TSLA, RIVN, LCID |
filter | Filter condition (required) | Chg > 5 | Chg < -5 |
reasons | Show re-evaluation triggers | reasons |
display | Custom columns | display Close[0..19].Average |
Example — monitor stocks for 3%+ moves with high volume:
ticker AAPL, MSFT, NVDA, TSLA Chg > 3 & Volume[0] > 1000000
reasons display Close[0..19].Average as "SMA20"
macro
Defines a reusable expression that can be referenced in filters and displayed as a column.
macro <id> = <expression> [as "name"] [: "description"]
The id can be up to 8 characters. Once defined, reference macros with the $ prefix.
macro SMA20 = Close[0..19].Average as "20-Day SMA"
macro RelVol = Volume[0] / AvgVolume as "Relative Volume"
query where Close[0] > $SMA20 & $RelVol > 2
You can also manage macros through the Macros Manager widget (M in the command terminal).
Filter Syntax
A filter expression follows the pattern:
<attribute>[<range>].<method> <operator> <value>
For example, Volume[0] > 1000000 filters for stocks where current volume exceeds 1 million shares.
Attributes
Price & Volume
| Attribute | Description | Aliases |
|---|---|---|
Open | Opening price | o |
High | High price | h |
Low | Low price | l |
Close | Closing price | c |
Last | Last traded price | price, p |
Chg | Price change % | change |
Volume | Volume | vol, v |
Money | Dollar volume (price x volume) |
Calculated
| Attribute | Description |
|---|---|
Range | High - Low |
TrueRange | max(High-Low, abs(High-PrevClose), abs(Low-PrevClose)) |
VWAP | Volume-weighted average price |
Bid | Best bid price |
Ask | Best ask price |
Fundamental
| Attribute | Description | Aliases |
|---|---|---|
MarketCap | Market capitalization | mktcap, cap, mc |
PE | Price-to-earnings ratio | p/e |
AvgVolume | Average daily volume | avgvol, av |
52wHigh | 52-week high | 52wh |
52wLow | 52-week low | 52wl |
Time Prefixes
Prefix an attribute to specify the timeframe:
| Prefix | Timeframe | Example |
|---|---|---|
M | Minute | MClose[0] — current minute close |
I | Intraday | IVolume[0..5] — intraday volume |
D | Daily | DVolume[1..5] — daily volume for last 5 days |
W | Weekly | WClose[0..4] — weekly close for last 4 weeks |
Ranges
Index 0 is always the most recent bar.
| Syntax | Meaning |
|---|---|
[0] | Current bar |
[1] | Previous bar |
[0..4] | Current through 4 bars ago (5 bars) |
[1..10] | Previous through 10 bars ago |
[9:30] | At 9:30 AM |
[9:30..16:00] | From 9:30 AM to 4:00 PM |
Aggregation Methods
Apply a method after a range to aggregate multiple bars into a single value.
Statistical
| Method | Description | Example |
|---|---|---|
Average | Simple moving average | Close[0..19].Average (20-day SMA) |
AvgExp | Exponential moving average | Close[0..11].AvgExp (12-bar EMA) |
Sum | Sum of values | Volume[0..4].Sum |
StdDev | Standard deviation | Close[0..19].StdDev |
WeightedAvg | Weighted average (recent = higher) | Close[0..9].WeightedAvg |
Min / Max
| Method | Description | Example |
|---|---|---|
Max | Maximum value | High[0..19].Max (20-day high) |
Min | Minimum value | Low[0..19].Min (20-day low) |
Range | Max minus min | Close[0..9].Range |
Trend & Runs
| Method | Description | Example |
|---|---|---|
Trend | Linear regression slope | Close[0..19].Trend |
Run | Consecutive bars in same direction | Close[0..9].Run |
SignedRun | Run with direction (+up, -down) | Close[0..9].SignedRun |
Operators
Comparison
> , < , = , # (not equal) , >= , <=
Math
+ , - , * , /
Logical
& (AND) , | (OR)
Precedence (highest to lowest): unary - → * / → + - → comparisons → & → |
Use parentheses to override:
(Close[0] > Close[1]) & (Volume[0] > Volume[1])
Symbol Lists
Inline
query AAPL, MSFT, GOOGL, NVDA where Chg > 0
References
| Prefix | Type | Example |
|---|---|---|
W.. | Watchlist | W..favorites |
X.. | Exchange | X..NYSE |
M.. | Industry | M..technology |
Q.. | Query | Q..gainers (saved query results) |
@ | Named list | @mylist |
ALL | Entire universe | query ALL where ... |
Display Columns
Use the display clause to add custom columns. You can use any attribute, expression, or macro:
display Close[0..19].Average as "SMA20", Volume[0] / AvgVolume as "RelVol"
Built-in columns include: last, bid, ask, open, high, low, close, chg, chg%, vol, avgvol, mktcap, pe, 52wh, 52wl.
Examples
High volume gainers — stocks up 5%+ with volume over 5M:
query where Chg > 5 & Volume[0] > 5000000
Breakout scanner — new 20-day highs with high relative volume:
query where High[0] >= High[0..19].Max & Volume[0] > AvgVolume * 1.5
Momentum filter — above 50-day SMA with positive trend:
query where Close[0] > Close[0..49].Average & Close[0..19].Trend > 0
Golden cross setup — price above 50-day SMA, which is above 200-day SMA:
query where Close[0] > Close[0..49].Average
& Close[0..49].Average > Close[0..199].Average
Volume spike — 3x average volume:
query where Volume[0] > AvgVolume * 3
Consecutive up days — stocks up 5+ days in a row:
query where Close[0..9].Run >= 5 & Close[0] > Close[1]
Value filter — low P/E with decent volume:
query where PE > 0 & PE < 15 & Volume[0] > 1000000
Using macros — define once, reuse everywhere:
macro RelVol = Volume[0] / AvgVolume as "Relative Volume"
macro ATR14 = TrueRange[0..13].Average as "14-Day ATR"
query where $RelVol > 3 & Chg > 0
display $RelVol, $ATR14
sorton Volume desc extract 20
Quick Reference
COMMANDS query, ticker, macro
ATTRIBUTES Open High Low Close Last Volume Chg Range
TrueRange VWAP Money Bid Ask
MarketCap PE AvgVolume 52wHigh 52wLow
PREFIXES M (Minute) I (Intraday) D (Daily) W (Weekly)
RANGES [0] [1..5] [9:30] [9:30..16:00]
METHODS Average AvgExp Max Min Range Sum StdDev
WeightedAvg Trend Slope Run SignedRun
COMPARISON > < = # >= <=
MATH + - * /
LOGICAL & (AND) | (OR)
MACROS $MacroName
SYMBOL LISTS W.. X.. M.. Q.. @name ALL