Querying the screener with code

The screener can be queried with a mini expression language that consists of logical operators (AND, OR, NOT) and comparison operators (<, >, <=, >=, =, !=).

examples:

priceToEarnings < priceToBook

get stocks where the price/earnings ratio is less than the price/book ratio


priceToEarnings < priceToBook * 12

get stocks where the price/earnings ratio is less than 12 times the price/book ratio


marketCap > 100000000000 or marketCap > 100b

stocks with a market cap greater than 100 billion


(priceToBook < 2) OR (priceToEarnings < 5)

parenthesis are optional, they can be helpful when you are unsure of the precedence of the operators.


The code must be entered in the code box, and the query can be combined with basic filters:



Tech or Healthcare stocks that dipped more than 20% this year and have a market cap bigger than 75% of all other stocks

not empty

priceToEarnings < 10

this will return stocks where priceToEarnings is less than 10 or "N/A" (empty)

priceToEarnings < 10 AND NOT empty(priceToEarnings)

this gets rid of stocks where priceToEarnings is empty

Numbers

Big numbers can be abbreviated with the suffixes: "m","b","t" for million, billion, trillion.

e.g:

marketCap > 1t

Available Keys

Available Operators

>, <, <=, >=, AND, OR, NOT, =, !=, +, -, *, /, %, abs, sqrt, empty, avg, min, max

Aggregate functions

There are three aggregate functions (avg, min, max) and they act as expected.

marketCap > avg(marketCap)

get stocks with a marketCap greater than the average marketCap of all stocks


aggregate functions can contain a subquery: avg(KEY,SUBQUERY)

marketCap > avg(marketCap,sector="Technology")

get stocks with a marketCap greater than the average marketCap of tech stocks


You can use the special this keyword inside a subquery to refer to the current stock being filtered

marketCap > avg(marketCap,sector=this.sector)

get stocks with a marketCap greater than the average of its corresponding sector.