Slang
A domain-specific scripting language for building and running trading strategies
What is Slang?
Slang is Traderoid's built-in scripting language. A Slang script is a sequence of variable-assignment statements that map one-to-one onto the visual node graph. Each line creates or updates a node, and the variable names become the node labels that connect everything together.
Because Slang is bi-directional — it can compile text into a live graph and also decompile a graph back into text — it acts as a portable, human-readable save format for strategies. The same language is also executed frame-by-frame by the Roid Runner to produce live signals without any graph UI.
Write Once, Run Everywhere
A Slang script saved to the library can be loaded into the graph editor for visual inspection, or executed directly by the Roid Runner for automated signals.
Full Parity with the Node Graph
Every node type in the graph editor has a corresponding Slang command. There is no capability gap between visual and scripted strategy building.
Type-Safe Arguments
Each command declares typed parameters. The compiler coerces values and throws human-readable errors on type mismatches, line numbers included.
Sub-pages
Architecture Overview
The Slang subsystem is composed of five layers. Each layer has a single responsibility and communicates with the next through well-defined interfaces.
parser/SlangParser.tsTokenises raw source text into SlangCommand objects. Registers and looks up command definitions via a global COMMANDS registry. Knows nothing about nodes or the DOM.
parser/Slang*Parser.tsEight side-effect modules (Source, Indicator, Logical, Math, Pattern, RiskManagement, Action, Chart, Config) that each call registerCommands() on import. Loaded by the compiler and runner at startup.
SlangCompiler.tsCalls parse(), walks each SlangCommand, creates or updates ReactFlow nodes via GraphCommands, resolves variable→nodeId mappings, removes stale nodes, then triggers Dagre layout + graph execution.
SlangDecompiler.tsBuilds a reverse map (nodeType → funcName), topologically sorts all nodes (Kahn's algorithm), then emits one Slang line per node. Also appends SetWindowSize and AddToChart config commands.
roidRunner/RoidRunner.tsCompiles a Slang script into an ordered array of CompiledSteps (closures). Each frame, every step is called in order — sources push one data point, compute steps call their IncrementalRunner. Powers live signals and backtesting replays.
Quick Example
A minimal moving-average crossover strategy in Slang:
// 1. Data source s = sc.STOCK("AAPL", "day", 1) // 2. Indicators fast = ta.SMA(s, 10) slow = ta.SMA(s, 50) // 3. Signal — crossover sig = dm.CROSSOVER(fast, slow) // 4. Risk management tp = rm.TAKEPROFIT(s, "percentage", 2.5) sl = rm.STOPLOSS(s, "percentage", 1.0) // 5. Open position pos = ex.OPENPOSITION(s, tp, sl, sig, "market_long", 10000) // 6. Display ch.AddToChart(0, fast, slow) cg.SetWindowSize(200)
sc.STOCKFetches AAPL daily OHLCV data. Variable s holds the node.
ta.SMA10- and 50-period simple moving averages of the data source.
dm.CROSSOVERFires a 1 signal when fast crosses above slow.
rm.TAKEPROFIT / STOPLOSS2.5 % TP and 1 % SL levels computed from the source OHLC.
ex.OPENPOSITIONMarket-long order node wired to source, TP, SL, and the crossover signal.
ch / cgDisplay fast and slow on chart 0; show 200 candles in the window.
Module Map
| File | Exports | Role |
|---|---|---|
| SlangParser.ts | parse, registerCommands, getCommandDef, listCommands, coerceParam | Core tokeniser + command registry |
| SlangNamespaces.ts | NAMESPACES, getCommandNamespace, validateNamespace, registerNamespaceCommands | Namespace definitions and reverse lookup |
| SlangCompiler.ts | compile, decompile (re-exported), setSlangGlobal, resetCompiler | Graph compiler — parse → create/update nodes → layout |
| SlangDecompiler.ts | decompile | Topological decompiler — nodes → Slang source text |
| SlangStore.ts | getSlangCode, setSlangCode, onSlangCodeChange, getCurrentSlang, setCurrentSlang | In-memory singleton for editor code and loaded script metadata |
| SlangLogger.ts | slangLogger (singleton) | Pub/sub logger: info / success / error entries with timestamps |
| SlangConfig.ts | defaultSlangEditorSettings, getSlangColors, getSlangEditorSettings, setSlangEditorSettings, subscribeToSlangEditorSettings | Colour palette + intellisense settings with localStorage persistence |
| SlangEditor.tsx | default SlangEditor | Full editor UI: textarea, highlight overlay, gutter, log panel, toolbar |
| SlangEditorHeader.tsx | default SlangEditorHeader | Top toolbar: Compile, Decompile, Open, Save buttons |
| SlangIntellisense.tsx | useSlangIntellisense, IntellisensePopup, useCommandHover, CommandHoverTooltip | Autocomplete hook + popup + hover tooltip components |
| parser/Slang*Parser.ts | (side-effect only) | Eight parser modules that self-register commands on import |
| roidRunner/RoidRunner.ts | compileRoid, runRoid, runRoidAsync | Frame-by-frame execution engine for live signals |
| roidRunner/RoidPositionState.ts | openPosition, closePosition, isPositionOpen, resetRoidPositionState, … | Single-position tracker shared between OPENPOSITION and CLOSEPOSITION runners |