Trading Strategy Domain Specific Language - Agencio Predict
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.
| Category | Count | Description | Key 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() |
| 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) |
The DSL Primitive Browser and Simple Strategy Builder are integrated at three key locations in the platform:
| Location | Component | Mode | Purpose |
|---|---|---|---|
| /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 |
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
}
| Template | Entry Condition | Exit 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 |
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
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
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
| Method | Path | Description |
|---|---|---|
| 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 |
| Component | Path | Lines |
|---|---|---|
| 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 |
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