Slang

A domain-specific scripting language for building and running trading strategies

7 Namespaces300+ CommandsCompile to GraphDecompile from GraphSyntax HighlightingIntellisenseFrame-by-Frame Runner

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.

1
SlangParserparser/SlangParser.ts

Tokenises raw source text into SlangCommand objects. Registers and looks up command definitions via a global COMMANDS registry. Knows nothing about nodes or the DOM.

2
Parser Modulesparser/Slang*Parser.ts

Eight 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.

3
SlangCompilerSlangCompiler.ts

Calls parse(), walks each SlangCommand, creates or updates ReactFlow nodes via GraphCommands, resolves variable→nodeId mappings, removes stale nodes, then triggers Dagre layout + graph execution.

4
SlangDecompilerSlangDecompiler.ts

Builds 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.

5
RoidRunnerroidRunner/RoidRunner.ts

Compiles 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:

strategy.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)
Line 1sc.STOCK

Fetches AAPL daily OHLCV data. Variable s holds the node.

Lines 2–3ta.SMA

10- and 50-period simple moving averages of the data source.

Line 4dm.CROSSOVER

Fires a 1 signal when fast crosses above slow.

Lines 5–6rm.TAKEPROFIT / STOPLOSS

2.5 % TP and 1 % SL levels computed from the source OHLC.

Line 7ex.OPENPOSITION

Market-long order node wired to source, TP, SL, and the crossover signal.

Lines 8–9ch / cg

Display fast and slow on chart 0; show 200 candles in the window.

Module Map

FileExportsRole
SlangParser.tsparse, registerCommands, getCommandDef, listCommands, coerceParamCore tokeniser + command registry
SlangNamespaces.tsNAMESPACES, getCommandNamespace, validateNamespace, registerNamespaceCommandsNamespace definitions and reverse lookup
SlangCompiler.tscompile, decompile (re-exported), setSlangGlobal, resetCompilerGraph compiler — parse → create/update nodes → layout
SlangDecompiler.tsdecompileTopological decompiler — nodes → Slang source text
SlangStore.tsgetSlangCode, setSlangCode, onSlangCodeChange, getCurrentSlang, setCurrentSlangIn-memory singleton for editor code and loaded script metadata
SlangLogger.tsslangLogger (singleton)Pub/sub logger: info / success / error entries with timestamps
SlangConfig.tsdefaultSlangEditorSettings, getSlangColors, getSlangEditorSettings, setSlangEditorSettings, subscribeToSlangEditorSettingsColour palette + intellisense settings with localStorage persistence
SlangEditor.tsxdefault SlangEditorFull editor UI: textarea, highlight overlay, gutter, log panel, toolbar
SlangEditorHeader.tsxdefault SlangEditorHeaderTop toolbar: Compile, Decompile, Open, Save buttons
SlangIntellisense.tsxuseSlangIntellisense, IntellisensePopup, useCommandHover, CommandHoverTooltipAutocomplete hook + popup + hover tooltip components
parser/Slang*Parser.ts(side-effect only)Eight parser modules that self-register commands on import
roidRunner/RoidRunner.tscompileRoid, runRoid, runRoidAsyncFrame-by-frame execution engine for live signals
roidRunner/RoidPositionState.tsopenPosition, closePosition, isPositionOpen, resetRoidPositionState, …Single-position tracker shared between OPENPOSITION and CLOSEPOSITION runners