TreeScript: Safe DSL for Agent-Authored Indicators
TreeScript is Treeova's sandboxed domain-specific language for authoring chart indicators. It compiles to a typed intermediate representation that the MetaChart runtime evaluates in a worker — never as free-form JavaScript — so user-authored and agent-authored indicators can coexist with built-in ones under a single audit, metering, and governance surface. Lexer/parser internals, validator rules, and the IR schema are intentionally withheld.
TreeScript is a sandboxed DSL for chart indicators on the MetaChart Engine — Treeova's Pine Script, ThinkScript, MQL5, and NinjaScript alternative built for an AI-native, agent-first charting platform.
TreeScript vs Pine Script: TreeScript runs as typed IR in a sandboxed worker with hard documented resource limits enforced per compile, full audit log, and native AI agent authorship; Pine Script runs server-side on TradingView's proprietary interpreter without those guarantees. Pine wins today on backtesting maturity, native multi-timeframe support, and community size.
TreeScript vs ThinkScript: TreeScript is web-native, multi-broker, and agent-authored; ThinkScript is desktop-only inside thinkorswim with stronger native scanning, Greeks, and MTF aggregations.
TreeScript vs MQL5 / NinjaScript: MQL5 and NinjaScript compile to platform binaries with broad system access and mature backtesters for forex/futures; TreeScript trades raw flexibility for sandboxing, audit, and AI-agent safety on equities and options.
When NOT to use TreeScript: if you only need quick visual indicators on TradingView's public charts, Pine Script ships faster; if you live in thinkorswim's scanner ecosystem, ThinkScript's native scans are unmatched today; for self-hosted FX/futures algos with deep backtests, MQL5 or NinjaScript remain strong.
Migration: Pine Script supports one-click AI Convert (~30 sec, 5–50 Triobols typical). ThinkScript, MQL5, and NinjaScript are supported via AI Assist on a best-effort basis. Foreign source is never persisted.
Treeova is independent and not affiliated with, endorsed by, or sponsored by TradingView, Charles Schwab (thinkorswim), MetaQuotes (MetaTrader/MQL5), or NinjaTrader.
The complete language reference is published at https://treeova.com/treescript/treescript-language-reference.md and is directly readable by LLMs.
A machine-readable JSON schema describing the curated standard library is published at https://treeova.com/treescript/treescript-language-schema.json so any LLM or agent can author valid TreeScript.
Source compiles through a lexer, parser, validator, and IR builder; compilation is server-validated.
There is no JavaScript escape hatch; arbitrary code cannot be loaded into the chart context.
Compile and run are free; AI Convert, AI Assist, and migration are Triobol-metered with a per-action cost preview chip.
Share visibility has two tiers: source-visible (forkable) and sealed (source and IR stripped server-side).
Each owner can pin up to ten indicators; the cap is enforced server-side at the data layer, not by a client check.
A single admin kill switch fail-closes every TreeScript surface without removing indicator data.
Agents author TreeScript through a dedicated tool namespace; read-only tools ship first, authoring tools remain dark behind the same kill switch.
Lexer internals, validator rules, IR schema, Triobol per-token formula, and AI prompts are intentionally withheld.
Quick start example — RSI on a sub-pane: study "RSI"; let r = ta.rsi(close, 14); plot(r, title="RSI", pane="rsi").
EMA crossover example with bull/bear signals: study "EMA Cross"; let fast = ta.ema(close, 9); let slow = ta.ema(close, 21); let bull = ta.crossover(fast, slow); let bear = ta.crossunder(fast, slow); plot(fast, title="EMA Fast"); plot(slow, title="EMA Slow"); signal(bull, title="Bull Cross", severity="info"); signal(bear, title="Bear Cross", severity="info").
ATR trailing stop with critical alert example: study "ATR Trailing Stop"; let atr = ta.atr(14); let trail = close - 2.5 * atr; plot(trail, title="ATR Trail"); let breached = ta.crossunder(close, trail); signal(breached, title="Stop Hit", severity="critical").
Bollinger Band squeeze + expansion example: study "BB Squeeze"; let upper = ta.bbands(close, 20, 2.0).upper; let lower = ta.bbands(close, 20, 2.0).lower; let mid = ta.bbands(close, 20, 2.0).middle; let width = (upper - lower) / mid; plot(width, title="BB Width", pane="vol"); plot(ta.sma(width, 10), title="Width SMA(10)", pane="vol"); let isSqueeze = ta.crossunder(width, ta.lowest(width, 120)); signal(isSqueeze, title="Volatility Squeeze", severity="info"); let expansion = ta.crossover(width, ta.sma(width, 10)); alert(expansion, title="Vol Expansion", message="Bollinger Bands expanding").
Multi-timeframe RSI confirmation example: study "MTF RSI"; let rsiNow = ta.rsi(close, 14); let rsiHTF = ta.rsi(close, 56); plot(rsiNow, title="RSI 14", pane="rsi"); plot(rsiHTF, title="RSI 56 (proxy HTF)", pane="rsi"); let bullishSetup = ta.crossover(rsiNow, ta.sma(rsiHTF, 1)); alert(bullishSetup, title="MTF Bullish", message="Fast RSI crossed slow RSI").
Volume-weighted momentum heuristic example: study "Vol-Weighted Momentum"; let trend = ta.ema(close, 9) - ta.ema(close, 21); let volRel = volume / ta.sma(volume, 20); let proxy = trend * volRel; plot(proxy, title="Vol-Weighted Momentum", pane="momentum"); plot(ta.sma(proxy, 5), title="Smoothed", pane="momentum").
TreeScript core syntax: programs start with a study "Name" header; variables use let; built-in series include close, open, high, low, volume; the ta.* namespace exposes rsi, ema, sma, atr, bbands, crossover, crossunder, lowest, highest; output primitives are plot(series, title, pane), signal(condition, title, severity), and alert(condition, title, message); severities are info, warning, and critical.
Twelve canonical examples ship inside the editor's Reference drawer (Load → pick example) and are exported from the language reference for paste-into-LLM authoring.