{"slug": "show-hn-monkql-a-typed-query-language-llms-write-to-scan-13k-stocks-in-130ms", "title": "Show HN: MonkQL – A typed query language LLMs write to scan 13k stocks in 130ms", "summary": "Monk.trade launched MonkQL, a typed query language that AI agents write to screen US stocks, ETFs and futures, with the company claiming a full US market scan returns in about a tenth of a second (roughly 130ms). MonkQL is not SQL or Python: prices, volumes and percentages are distinct types so mismatched comparisons fail to compile, queries can only look backward (close[1] is one bar ago, with no way to write tomorrow), loops have fixed bounds, calls time out at 30 seconds, and nothing runs until the whole query compiles. Monk.trade operates as an MCP server that connects to ChatGPT or Claude, letting any MCP-speaking agent write short, human-readable queries that the compiler checks before any data is read.", "body_md": "# Introducing MonkQL: the stock-research language your AI agent writes\n\nAsk your AI agent for a breakout, a pullback or a tight range, and it writes a short MonkQL query you can read. The compiler checks it before any data is read.\n\nPublished\n\nMonk.trade is an app you add to ChatGPT or Claude for researching US stocks, ETFs and futures. [Connect ChatGPT](https://monk.trade/help/chatgpt) or [Connect Claude](https://monk.trade/help/claude).\n\nMonkQL is the language your AI agent writes when you ask Monk.trade a question about the market. Monk.trade is an MCP server, so any agent that speaks MCP can use it. You ask in plain words. The agent writes a few lines of MonkQL, Monk.trade compiles and runs them, and the agent reads back the rows and charts. The query stays short enough for you to check, and a scan of the whole US market comes back in about a tenth of a second.\n\nMonkQL is its own language, not SQL or Python, because the agent writes it and you read it. A query only looks back: `close[1]` is one bar ago, and there is no way to write tomorrow. Prices, volumes and percentages are types, so comparing a price with a volume fails to compile rather than returning nothing. Loops have fixed bounds, a call has 30 seconds, and nothing runs until the whole query compiles. Filings and financials count from when they became public.\n\nEvery example below is a real session: a question in plain words, the MonkQL the agent wrote, and the result Monk.trade returned. Line breaks are added to fit the page.\n\n## A setup is a few lines\n\nWe asked for liquid common stocks that broke above their prior 20-day high on at least twice their average volume. The agent wrote:\n\n```\nfrom stocks on daily\ninclude type == \"common\"\nwhere sma(close * volume, 20)[1] >= 20000000\n  and close > highest(high, 20)[1]\n  and volume >= 2 * sma(volume, 20)[1]\nshow close,\n  highest(high, 20)[1] as breakout_level,\n  100 * (close / highest(high, 20)[1] - 1) as pct_above,\n  volume / sma(volume, 20)[1] as vol_ratio,\n  100 * (close / close[1] - 1) as day_chg\nsort 100 * (close / highest(high, 20)[1] - 1) desc\ntake 50\n```\n\nA series like `close` or `volume` is the whole history, and `[n]` reads it `n` bars back. `highest(high, 20)[1]` is the highest high of the 20 sessions before today, so today’s bar can break it. `sma(close * volume, 20)[1] >= 20000000` keeps stocks that trade at least $20M a day on average; most scans below start with it. The agent then ran the scan on the last completed session and charted the strongest result with the level marked:\n\n## Names for the parts\n\nA pullback in an uptrend has more parts, and `let` names them:\n\n``` js\nfrom stocks on daily\ninclude type == \"common\"\nlet e20 = ema(close, 20)\nlet s50 = sma(close, 50)\nwhere sma(close * volume, 20)[1] >= 20000000\n  and e20 > s50\n  and e20 > e20[5]\n  and s50 > s50[5]\n  and low <= e20\n  and close > e20\n  and volume < 0.8 * sma(volume, 20)[1]\nshow close, e20 as ema20, s50 as sma50,\n  100 * (low / e20 - 1) as low_vs_ema_pct,\n  volume / sma(volume, 20)[1] as rel_vol,\n  count(close > e20, 30) as days_above_ema_30,\n  roc(e20, 20) as ema20_roc20\nsort count(close > e20, 30) desc\ntake 25\n```\n\nEach line of `where` is one rule of the setup: the 20-day EMA above the 50-day average, both higher than a week ago, a low that touched the EMA, a close back above it, and volume under 80% of normal. `count(close > e20, 30)` counts the sessions out of the last 30 that closed above the EMA, so sorting by it puts the steadiest trends first.\n\n## Ranges and levels\n\nFor stocks coiling near their highs, the agent defined the 10-day range as a percentage of price and kept those at their tightest of the last 60 sessions, within 5% of the 52-week high:\n\n``` js\nfrom stocks\ninclude type == \"common\"\nlet rng = 100 * (highest(high, 10) - lowest(low, 10)) / close\nwhere sma(close * volume, 20)[1] >= 20000000\n  and rng <= lowest(rng, 60)\n  and close >= 0.95 * highest(high, 252)\nshow close, rng as range10_pct,\n  100 * (close / highest(high, 252) - 1) as from_52w_high_pct,\n  sma(close * volume, 20) as dollar_vol20\nsort rng asc\ntake 25\n```\n\n`lowest(rng, 60)` works on a series the query defined, the same as on `close`. Charts take expressions too: `mark level highest(high, 10)` draws whatever the expression evaluates to on the newest bar.\n\n## Every timeframe in one call\n\nA line `---` separates up to five queries in one call, as in the clip at the top. `on` picks the interval, and `@daily` reads the daily series from inside an intraday query, so `high@daily[1]` is the prior session’s high on a regular-session 5-minute chart.\n\nExtended hours work the same way: `on 5m premarket` runs on premarket bars, where `close@daily` is the last regular close. This is how the agent found premarket gaps:\n\n```\nfrom stocks on 5m premarket\ninclude type == \"common\"\nwhere 100 * (close / close@daily - 1) >= 3 and volume@premarket >= 10000\nshow 100 * (close / close@daily - 1) as gap_pct,\n  close as pm_last,\n  volume@premarket as pm_volume\nsort 100 * (close / close@daily - 1) desc\ntake 100\n```\n\n## Across the market\n\nCross-sectional functions compare each stock with the rest of the scan. Asked for the stock that led each sector over 20 sessions, the agent wrote:\n\n```\nfrom stocks\ninclude type == \"common\" and sma(close * volume, 20)[1] >= 20000000\nwhere rank(roc(close, 20) by sector) == 1\nshow sector, roc(close, 20) as ret20, close,\n  sma(close * volume, 20)[1] as dollar_vol\nsort roc(close, 20) desc\ntake 50\n```\n\n| Sector | Stock | 20-session return | \n|---|---|---|\n| Information Technology | BMBL | +135.4% | \n| Health Care | NAUT | +116.2% | \n| Consumer Discretionary | FIGS | +50.7% | \n| Industrials | OLB | +43.6% | \n| Energy | RRC | +38.8% | \n| Financials | CBOE | +33.6% | \n| Real Estate | CCI | +32.3% | \n| Consumer Staples | LW | +24.7% | \n| Communication Services | TRI | +24.7% | \n| Materials | CLF | +24.6% | \n| Utilities | PNW | +15.8% | \n\n`include` sets the population a rank is taken over and `where` filters after ranking, so “first in its sector” means first among liquid common stocks, not first among whatever survived other filters. `percentile`, `share`, `cs_mean` and `cs_median` work the same way. A group smaller than 20 stocks is reported as undecided rather than ranked.\n\n## Your own functions\n\nMonkQL has no built-in linear regression. We asked the agent to write one, and it did, in one expression:\n\n```\nfn linreg_slope(x, n) =\n  6 * ((n - 1) * sum(i in 0..n - 1 : x[i]) - 2 * sum(i in 0..n - 1 : i * x[i]))\n    / (n * (n * n - 1))\nlet slope = linreg_slope(close, 50)\non daily\ninclude type == \"common\" and close >= 5 and sma(close * volume, 20)[1] >= 20000000\nwhere slope > 0 and count(crossover(slope, 0), 5) >= 1 and close > sma(close, 200)\nshow close, slope as slope_per_day,\n  100 * slope / close as slope_pct_per_day unit percent,\n  since(crossover(slope, 0), 5) as turned_bars_ago,\n  100 * (close / sma(close, 200) - 1) as above_200d unit percent,\n  sma(close * volume, 20) as dollar_vol_20d\nsort sma(close * volume, 20) desc\ntake 50\n```\n\n`fn` defines a function, and `sum(i in 0..n - 1 : …)` is a bounded loop over bar offsets. This is the least-squares slope in closed form. A function can only call functions defined before it, so a function cannot call itself and every call finishes.\n\nThe library grows slowly on purpose. We hold out 48 published daily scans for testing, and a new built-in has to be needed by at least two of them. Linear regression is needed by one, so you write it yourself.\n\n## Compile errors with hints\n\nAgents know the function names other tools use, so the likely mistake is borrowing one. The compiler turns it into a correction before any data is read:\n\n- Spelling is forgiving: case, a `ta.` or`math.` prefix and underscores are ignored, so`TA.SMA` is`sma` and`cross_over` is`crossover` .\n- Vocabulary is not. `MA` and`HHV` are errors whose hints name`sma` and`highest` , because a name from another tool can carry that tool’s meaning. The only synonyms are`avg` and`mean` for`sma` ,`sum` of a condition for`count` , and`if(c, a, b)` for`c ? a : b` .\n- Expressions carry units. Prices, volumes, ratios and percentages are different types, so `close > volume` is “cannot compare price with volume”, not an empty result.\n- `[n]` only counts back. A written negative offset is a compile error, because it would read the future.\n- The parser recovers at the next clause and the checker keeps going, so one compile reports every problem it can find.\n\nEvery query that compiles comes back in a canonical form, with keywords and names in lower case, one clause per line, numbers in one notation and defaults such as `from universe all`, `on daily` and `take 100` written out. Queries that differ only in case, spacing, clause order, synonyms or omitted defaults print the same text and share a digest. The result carries that text, so you can see exactly what ran.\n\n## Fast enough to ask again\n\nAn agent works by asking, reading and asking again, so every query has to come back before the conversation moves on. Ranking every sector across all 13,270 US-listed symbols took 129 milliseconds of server time; the breakout scan took 133 and the regression scan 173. Each result also reports what it set aside and could not decide, so the agent can say what it left out.\n\n## How it runs\n\nThe compiler is Rust: a lexer, a recursive-descent parser, a checker for names, types and units, and a planner. The plan is a deduplicated expression graph, so `sma(close, 20)` used in `where`, `show` and a chart mark is computed once per stock, with the warm-up history recursive functions like `ema` need. Evaluation runs per stock over column buffers, and a node is computed on first demand, so a stock that fails the first `where` condition computes nothing else.\n\nThe language is about 41,000 lines of Rust with 560 tests, among them generative tests that compile random programs, valid and broken, and print the seed of any failure.\n\n## Beyond stocks and price\n\nThe same language runs on 34 futures contracts with `from futures`, and saved queries keep a version history you can rerun. The same expressions also read SEC filings, Form 4 insider trades, reported financials and news as series aligned with the bars, each counted from when it was published or filed, never from the date it describes. That is a post of its own.\n\n## Try it\n\nConnect Monk.trade to your agent with the guides for [ChatGPT](https://monk.trade/help/chatgpt), [Claude](https://monk.trade/help/claude) or [other MCP apps](https://monk.trade/help/other-apps), then ask for a setup in plain words. The quickstart and the full MonkQL reference are served to the agent with the tools, and the agent will show you every query it runs.\n\n- A call holds at most five queries in 8,192 bytes and has 30 seconds.\n- Market-wide scans start from active US stocks (premarket and after-hours scans skip that floor); ETFs and other types stay in unless the query filters them, as these examples do with `type == \"common\"` .\n- Queries are read-only.\n\nResearch only. Not investment advice. [Read the risk notice](https://monk.trade/risk)", "url": "https://wpnews.pro/news/show-hn-monkql-a-typed-query-language-llms-write-to-scan-13k-stocks-in-130ms", "canonical_source": "https://monk.trade/blog/introducing-monkql", "published_at": "2026-12-03 13:26:21+00:00", "updated_at": "2026-12-03 13:47:57.110589+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "developer-tools", "ai-products"], "entities": ["MonkQL", "Monk.trade", "ChatGPT", "Claude", "MCP"], "also_reported_by": [], "takeaway": "MonkQL's type system rejects comparisons like price against volume at compile time and its backward-only series syntax (close[1], no future bars) constrains what an agent can express, so queries stay short enough for a human to check before execution.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/show-hn-monkql-a-typed-query-language-llms-write-to-scan-13k-stocks-in-130ms", "markdown": "https://wpnews.pro/news/show-hn-monkql-a-typed-query-language-llms-write-to-scan-13k-stocks-in-130ms.md", "text": "https://wpnews.pro/news/show-hn-monkql-a-typed-query-language-llms-write-to-scan-13k-stocks-in-130ms.txt", "jsonld": "https://wpnews.pro/news/show-hn-monkql-a-typed-query-language-llms-write-to-scan-13k-stocks-in-130ms.jsonld"}}