DSL Primitive Browser & Strategy Builder

Trading Strategy Domain Specific Language - Agencio Predict

417
Primitives
14
Categories
60+
PINN Primitives
4
Horizons
417 Primitives Available: Across 14 categories including price, technical, sentiment, macro, pattern, options, PINN, fundamental, position, sizing, prediction markets, composer, weather, and LLM.
What is DSL? The Domain Specific Language (DSL) is a declarative way to define trading strategies using pre-built signal primitives. Each primitive is a function that returns data (prices, indicators, signals) which you combine with conditions to create entry/exit rules.

Table of Contents

1. System Overview

The DSL system enables users to create trading strategies without writing code. Primitives are building blocks that return values (numbers, booleans, strings) which are combined using operators and logic to form trading rules.

DSL System Architecture
flowchart TB subgraph UserInput["User Input Methods"] NL["Natural Language\nFrom English"] VB["Visual Builder\nGuided Builder"] DSL["Manual DSL\nWrite DSL"] TPL["Templates\nPre-built strategies"] end subgraph DSLCore["DSL Core System"] PARSE["DSL Parser\nYAML to AST"] VALID["Validator\nPrimitive whitelist"] EVAL["Evaluator\nBar-by-bar execution"] end subgraph Primitives["417 Primitives"] P1["Price (32)\nprice, volume, vwap"] P2["Technical (85)\nrsi, macd, sma, bb"] P3["Sentiment (28)\nnews, social, analyst"] P4["Macro (24)\nvix, yield_curve, fed"] P5["Pattern (35)\nfvg, candlestick, sr"] P6["Options (18)\niv, put_call, gamma"] P7["PINN (60+)\nneural network signals"] P8["Others (135)\nfundamental, sizing, etc"] end subgraph Execution["Execution Layer"] BACKTEST["Backtest Engine\n90-day historical"] PAPER["Paper Executor\nSimulated trading"] LIVE["Live Executor\nReal broker orders"] end NL --> |"LLM Translation"| PARSE VB --> |"Generate YAML"| PARSE DSL --> PARSE TPL --> PARSE PARSE --> VALID VALID --> EVAL P1 & P2 & P3 & P4 & P5 & P6 & P7 & P8 --> EVAL EVAL --> BACKTEST & PAPER & LIVE

2. Primitive Categories (14)

Category Overview
flowchart TB subgraph MarketData["Market Data"] PRICE["Price\n32 primitives"] TECH["Technical\n85 primitives"] PATTERN["Pattern\n35 primitives"] end subgraph AlternativeData["Alternative Data"] SENT["Sentiment\n36 primitives"] MACRO["Macro\n24 primitives"] PRED["Prediction Markets\n12 primitives"] end subgraph Derivatives["Derivatives"] OPT["Options\n18 primitives"] FUND["Fundamental\n22 primitives"] end subgraph AI["AI/ML"] PINN["PINN\n60+ primitives"] LLM["LLM\n8 primitives"] end subgraph Trading["Trading"] POS["Position\n15 primitives"] SIZE["Sizing\n12 primitives"] COMP["Composer\n10 primitives"] WEATHER["Weather\n6 primitives"] end

Category Details

CategoryCountDescriptionKey Primitives
Price 32 Real-time and historical price, volume, VWAP data price(), volume(), vwap(), price_change()
Technical 85 Technical indicators: RSI, MACD, moving averages, Bollinger Bands, GARCH, volatility models rsi(14), macd(), sma(50), garch_volatility()
Sentiment 36 News, social media, analyst ratings, fear/greed, insider activity, mailbox/email intelligence sentiment("reddit", "24h"), fear_greed_index(), mailbox_sentiment(), mailbox_consensus_score()
Macro 24 VIX, yield curve, Fed funds, regime detection, sector rotation vix(), yield_curve_slope(), markov_regime()
Pattern 35 FVG zones, candlestick patterns, support/resistance, DTW templates fvg_bullish(), hammer(), dtw_template_match()
Options 18 Implied volatility, put/call ratio, gamma exposure, IV term structure iv_rank(), put_call_ratio(), vol_selling_signal()
PINN 60+ Physics-Informed Neural Network predictions: direction, volatility, sizing, correlation, regime pinn_direction(), pinn_confidence(), pinn_optimal_size()
Fundamental 45+ P/E ratio, earnings, institutional holdings, activist investors, crisis resilience pe_ratio(), institutional_ownership_pct(), resilience_score()
Position 20+ Current position info, P&L, drawdown, factor VaR, stress testing position_pnl_pct(), drawdown_from_peak(), factor_var()
Sizing 12 Kelly criterion, volatility-adjusted sizing, risk parity kelly(0.04, 5000), risk_parity_weight()
Prediction Markets 17 Polymarket, Kalshi probabilities, wallet clustering, fraud detection prediction_market_prob("fed-rate-cut"), polymarket_manipulation_risk()
Composer 3 Combine signals: all, any, xor all(signals), any(signals), xor(a, b)
Weather 20+ El Nino, hurricanes, temperature, climate indicators el_nino_index(), hurricane_season(), climate_risk()
LLM 1 AI-powered analysis and confirmation llm_confirms("claim", 0.7)

3. User Flow

Strategy Creation User Journey
flowchart TB subgraph Entry["Entry Points"] ALG["Trading > Algorithms\nPrimitives Tab"] WIZ["AI Trader Wizard\nGuided Builder"] SMART["Smart Portfolio\nStep 3 Strategies"] end subgraph Browse["Browse Primitives"] SEARCH["Search by name\nor description"] FILTER["Filter by\ncategory"] EXPAND["Expand category\nview details"] end subgraph Learn["Learn Primitive"] DESC["Read description"] ARGS["See arguments\nand return type"] EXAMPLE["Copy example\nusage"] end subgraph Build["Build Strategy"] ENTRY["Define entry\nconditions"] EXIT["Define exit\nconditions"] RISK["Set risk\nparameters"] end subgraph Test["Test Strategy"] BACK["Run backtest\n90 days"] WALK["Walk-forward\nvalidation"] STRESS["Regime stress\ntest"] end subgraph Deploy["Deploy"] PAPER["Start paper\ntrading"] LIVE["Go live\nafter graduation"] end ALG & WIZ & SMART --> SEARCH & FILTER SEARCH & FILTER --> EXPAND EXPAND --> DESC & ARGS & EXAMPLE DESC & ARGS & EXAMPLE --> ENTRY ENTRY --> EXIT --> RISK RISK --> BACK --> WALK --> STRESS STRESS --> PAPER --> LIVE

4. Integration Points

The DSL Primitive Browser and Simple Strategy Builder are integrated at three key locations in the platform:

Integration Architecture
flowchart TB subgraph Components["Shared Components"] BROWSER["DSLPrimitiveBrowser\npackages/fe/components/algorithms/"] BUILDER["SimpleStrategyBuilder\npackages/fe/components/algorithms/"] end subgraph Location1["Trading > Algorithms"] TAB1["Primitives Tab"] VIEW1["Full browser view\nwith categories"] end subgraph Location2["AI Trader Wizard"] STEP1["Welcome Step\nGuided Builder option"] STEP2["Create Step\nCollapsible browser"] end subgraph Location3["Smart Portfolio Wizard"] STEP3["Step 3 Strategies\nExplore DSL button"] BUILD3["Build Custom\nbutton"] end BROWSER --> TAB1 & STEP2 & STEP3 BUILDER --> STEP2 & BUILD3 TAB1 --> VIEW1 STEP1 --> STEP2 STEP3 --> BUILD3

Integration Details

LocationComponentModePurpose
/algorithms (Primitives tab) DSLPrimitiveBrowser Full Browse all 417 primitives with full descriptions
AI Trader Wizard (Create step) DSLPrimitiveBrowser + SimpleStrategyBuilder Collapsible Reference primitives while building strategy
Smart Portfolio Wizard (Step 3) DSLPrimitiveBrowser + SimpleStrategyBuilder Compact Explore and customize generated strategies

5. Primitive Browser Component

Primitive Browser UI Structure
flowchart TB subgraph Header["Header Section"] HELP["What are DSL Primitives?\nExplanation with example"] end subgraph Search["Search & Filter"] INPUT["Search input\nFilter by name/description"] CATS["Category chips\nClick to filter"] COUNT["Result count\nX primitives found"] end subgraph CategoryView["Category Accordion"] CAT1["Price (32)\nExpand/collapse"] CAT2["Technical (85)\nExpand/collapse"] CAT3["...\n14 categories total"] end subgraph PrimitiveCard["Primitive Details"] NAME["Primitive name\nwith arguments"] TYPE["Return type\nnumber/boolean/string"] DESC["Description"] BTN["Copy button\nInsert into editor"] end subgraph Footer["Quick Reference"] OPS["Operators\n< > <= >= == != && ||"] LOGIC["Logic\nall any count threshold"] DUR["Durations\n1h 4h 24h 7d"] end Header --> Search --> CategoryView CAT1 & CAT2 & CAT3 --> PrimitiveCard PrimitiveCard --> Footer

Component Props

interface DSLPrimitiveBrowserProps {
  primitives: PrimitiveSpec[];      // Array of all primitives
  onInsert?: (text: string) => void; // Insert into editor callback
  onSelectPrimitive?: (name: string) => void; // Selection callback
  className?: string;                // Additional CSS classes
  compact?: boolean;                 // Hide header/footer for embedding
}

6. Simple Strategy Builder

Strategy Builder Flow
flowchart TB subgraph Templates["Quick Start Templates"] T1["RSI Mean Reversion"] T2["Golden Cross"] T3["Sentiment Breakout"] T4["Fear & Greed Contrarian"] end subgraph Config["Basic Configuration"] NAME["Strategy Name"] SYMBOL["Symbol\nAAPL, BTC-USD, etc"] end subgraph Entry["Entry Conditions (AND)"] E1["Primitive dropdown\nrsi, sma, sentiment..."] E2["Operator\n< > <= >= == !="] E3["Value\nnumber or primitive"] E4["+ Add condition"] end subgraph Exit["Exit Conditions (ANY)"] X1["Primitive dropdown"] X2["Operator"] X3["Value"] X4["+ Add condition"] end subgraph Risk["Risk Settings"] R1["Max Position USD"] R2["Stop Loss %"] end subgraph Output["Generated DSL"] YAML["YAML output\nReady to use"] COPY["Copy button"] CREATE["Create Strategy button"] end T1 & T2 & T3 & T4 --> Config Config --> Entry --> Exit --> Risk --> Output

Default Templates

TemplateEntry ConditionExit Condition
RSI Mean Reversion rsi(14) < 30 rsi(14) > 70
Golden Cross sma(50) > sma(200) AND rsi(14) < 70 sma(50) < sma(200)
Sentiment Breakout sentiment("reddit", "24h") > 0.6 AND vix() < 20 sentiment("reddit", "24h") < 0.3
Fear & Greed Contrarian fear_greed_index() < 25 fear_greed_index() > 75

7. Strategy Examples

Example 1: RSI + Moving Average Strategy

strategy: "RSI + MA Crossover"
mode: paper
universe: [AAPL]

signals:
  entry:
    - rsi(14) < 30
    - sma(50) > sma(200)
  exit:
    - rsi(14) > 70

entry:
  when: all(entry)
  size: kelly(0.04, 5000)

exit:
  when: any(exit)

risk:
  max_position_usd: 5000
  stop_loss_pct: 3
  max_daily_loss_pct: 2

Example 2: PINN + Sentiment Strategy

strategy: "AI-Enhanced Momentum"
mode: paper
universe: [SPY]

signals:
  entry:
    - pinn_is_bullish("SPY", 0.6)
    - pinn_crisis_warning() < 0.3
    - sentiment("news", "24h") > 0.5
  exit:
    - pinn_is_bearish("SPY", 0.5)
    - position_pnl_pct() > 5

entry:
  when: all(entry)
  size: pinn_optimal_size("SPY", 30)

exit:
  when: any(exit)

risk:
  max_position_usd: 10000
  stop_loss_pct: 5
  trailing_stop_pct: 3

Example 3: Pattern + Macro Strategy

strategy: "Pattern Breakout"
mode: paper
universe: [QQQ]

signals:
  entry:
    - fvg_bullish()
    - vix() < 25
    - volume_z("", "20d") > 1.5
  exit:
    - fvg_bearish()
    - vix() > 35

entry:
  when: all(entry)
  size: volatility_size(2, 0.02)

exit:
  when: any(exit)

risk:
  max_position_usd: 8000
  stop_loss_pct: 4

8. API Reference

Endpoints

MethodPathDescription
GET /api/predict/v1/algorithms/primitives Get all 417 primitives with metadata
POST /api/predict/v1/algorithms/from-english Translate natural language to DSL
POST /api/predict/v1/algorithms/validate Validate DSL syntax and primitives
POST /api/predict/v1/algorithms Create algorithm from DSL

File References

ComponentPathLines
DSLPrimitiveBrowser packages/fe/src/components/algorithms/DSLPrimitiveBrowser.tsx ~450
SimpleStrategyBuilder packages/fe/src/components/algorithms/SimpleStrategyBuilder.tsx ~413
DSL Evaluator packages/be/src/algorithms/dsl/evaluator.ts ~2000
DSL Types packages/be/src/algorithms/dsl/types.ts ~2500
Primitives API packages/be/src/algorithms/api/handlers.ts ~600

9. Complete Primitive Reference (417)

Below is the complete reference of all 417 DSL primitives, organized by category. Each primitive shows its name, arguments, return type, and description.

Loading primitives...


DSL Primitive Browser Documentation - Agencio Predict
Generated: 2026-05-20 | 417 Primitives | 14 Categories
Integrated with AI Trader Wizard and Smart Portfolio Wizard