Barfinex
Loading

Blog

ReleaseBarfinex Team

Detector Rule Engine: Typed Strategy Signals in Barfinex

Write strategies as typed configs — conditions, weights, and thresholds. Produce immutable candidates with full Detector attribution.

#detector#rule-engine#strategy#signals
Detector rule engine reviewing market signals through transparent risk and validation gates

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 become immutable Detector candidates. Advisor does not rescore them; it only validates their signed evidence and applies a pinned admission policy.

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 Policy Admission

The candidate keeps Detector's rule attribution and deterministic basis. Advisor verifies hashes and signed Provider evidence, then records ADMIT or REJECT without AI, market analysis, or sizing.

Better rules → better candidates; Advisor preserves the boundary instead of duplicating Detector logic.

Get Started

Let’s Get in Touch

Have questions or want to explore Barfinex? Send us a message.