Blog
Detector Rule Engine: Define Strategies in TypeScript
Write trading strategies as typed configs — conditions, weights, thresholds. Get scored signals with full attribution that feed directly into Advisor's AI pipeline.
What It Is
The Detector rule engine lets you define trading strategies as structured TypeScript objects instead of imperative code. Three sections: inputs, rules, thresholds.
Signals from the rule engine feed directly into Advisor's 8-stage AI pipeline. Better rule definitions = better AI decisions.
How It Works
Inputs — what data to use
inputs: {
candles: { symbol: 'BTCUSDT', timeframe: '5m' },
orderflow: { symbol: 'BTCUSDT', depth: 10 },
}
Data is fetched from Provider automatically.
Rules — what to look for
rules: [
{
id: 'ema_trend_aligned',
description: 'Price above 20 EMA on 5m',
condition: ({ candles }) => candles.close > candles.ema(20),
weight: 2.0,
direction: 'long',
},
{
id: 'orderflow_imbalance',
description: 'Buy flow exceeds sell by > 30%',
condition: ({ orderflow }) => orderflow.buyRatio > 0.65,
weight: 1.5,
direction: 'long',
},
{
id: 'volume_spike',
description: 'Volume 2x above 20-period average',
condition: ({ candles }) => candles.volume > candles.avgVolume(20) * 2,
weight: 1.0,
direction: 'long',
},
]
Each fired rule adds its weight to the total score.
Thresholds — when to signal
thresholds: {
long: { min: 3.5 },
short: { min: 3.5 },
}
First two rules fire = score 3.5 (at threshold). All three = 4.5.
What You Get
- Full attribution — see exactly which rules fired for each candle and why
- Standardized scoring — all strategies use the same scale, making comparison easy
- Instance isolation — one broken rule doesn't affect other strategies
- Plain TypeScript — typed, autocompleted, versioned in git
Multiple Strategies
Run as many Detector instances as you want:
- Different strategies for different market regimes
- Different instances for different assets
- A/B test rule weights on the same symbol
How It Feeds AI
The signal's rule attribution passes to Advisor's pipeline. The LLM receives structured rule data instead of raw indicators — producing more grounded decisions.
Better rules → better signals → better AI decisions.
Get Started
- Detector API reference — full config schema
- Detector installation guide — set up your first instance
- See the
advisor-llm-hybridexample in the repo for a production-ready config