Docs
Widget Builder Language

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"]
ClauseDescriptionExample
symbolsSymbol list to scan (defaults to all)AAPL, MSFT or W..mylist
whereFilter conditionwhere Volume[0] > 1000000
sortonSort results by fieldsorton Volume desc
displayCustom columns to showdisplay Close[0..19].Average as "SMA20"
extractLimit resultsextract desc 10 (top 10)
asName the queryas "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>]
ClauseDescriptionExample
symbolsSymbols to monitorTSLA, RIVN, LCID
filterFilter condition (required)Chg > 5 | Chg < -5
reasonsShow re-evaluation triggersreasons
displayCustom columnsdisplay 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

AttributeDescriptionAliases
OpenOpening priceo
HighHigh priceh
LowLow pricel
CloseClosing pricec
LastLast traded priceprice, p
ChgPrice change %change
VolumeVolumevol, v
MoneyDollar volume (price x volume)

Calculated

AttributeDescription
RangeHigh - Low
TrueRangemax(High-Low, abs(High-PrevClose), abs(Low-PrevClose))
VWAPVolume-weighted average price
BidBest bid price
AskBest ask price

Fundamental

AttributeDescriptionAliases
MarketCapMarket capitalizationmktcap, cap, mc
PEPrice-to-earnings ratiop/e
AvgVolumeAverage daily volumeavgvol, av
52wHigh52-week high52wh
52wLow52-week low52wl

Time Prefixes

Prefix an attribute to specify the timeframe:

PrefixTimeframeExample
MMinuteMClose[0] — current minute close
IIntradayIVolume[0..5] — intraday volume
DDailyDVolume[1..5] — daily volume for last 5 days
WWeeklyWClose[0..4] — weekly close for last 4 weeks

Ranges

Index 0 is always the most recent bar.

SyntaxMeaning
[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

MethodDescriptionExample
AverageSimple moving averageClose[0..19].Average (20-day SMA)
AvgExpExponential moving averageClose[0..11].AvgExp (12-bar EMA)
SumSum of valuesVolume[0..4].Sum
StdDevStandard deviationClose[0..19].StdDev
WeightedAvgWeighted average (recent = higher)Close[0..9].WeightedAvg

Min / Max

MethodDescriptionExample
MaxMaximum valueHigh[0..19].Max (20-day high)
MinMinimum valueLow[0..19].Min (20-day low)
RangeMax minus minClose[0..9].Range

Trend & Runs

MethodDescriptionExample
TrendLinear regression slopeClose[0..19].Trend
RunConsecutive bars in same directionClose[0..9].Run
SignedRunRun 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

PrefixTypeExample
W..WatchlistW..favorites
X..ExchangeX..NYSE
M..IndustryM..technology
Q..QueryQ..gainers (saved query results)
@Named list@mylist
ALLEntire universequery 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