fintech-algorithms

Tick-Imbalance Bars

Install and import

bash
npm install fintech-algorithms
ts
import { constructBars } from "fintech-algorithms/market-data-engineering/bar-construction/tick-imbalance-bars";

Signature

constructBars(trades, config)

Closes a bar when signed tick flow becomes unusually one-sided relative to what recent history led you to expect. Bars are emitted on *information* rather than on elapsed time or traded quantity.

Parameters

NameTypeNotes
tradesTrade[]The raw tape in chronological order. Each trade carries tradeId, timestamp, session, symbol, price, volume and currency.
config{ initialTickSign: number; initialExpectedTicks: number; initialExpectedTickImbalance: number; alphaTicks: number; alphaTickImbalance: number; thresholdFloor: number; thresholdMultiplier: number; closePartial?: boolean }The initial* values seed the expectations before any bar has closed; the alpha* values are the EWMA decay rates that update them afterwards. thresholdFloor and thresholdMultiplier bound the resulting threshold so it cannot collapse toward zero in quiet periods.

Returns

Bar[] · length fewer

One bar per imbalance event, with the threshold that triggered it recorded on the bar.

Errors

  • When any alpha falls outside 0…1, or a seed expectation is not positive — throws

Complexity: time O(n), space O(bars).

Worked example

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input

trades
[
  {
    "tradeId": "T0001",
    "timestamp": "2026-01-05T14:30:00.000Z",
    "session": "2026-01-05",
    "symbol": "SYNTH",
    "price": 99.99,
    "volume": 36,
    "currency": "USD"
  },
  {
    "tradeId": "T0002",
    "timestamp": "2026-01-05T14:30:04.000Z",
    "session": "2026-01-05",
    "symbol": "SYNTH",
    "price": 99.99,
    "volume": 73,
    "currency": "USD"
  },
  {
    "tradeId": "T0003",
    "timestamp": "2026-01-05T14:30:07.000Z",
    "session": "2026-01-05",
    "symbol": "SYNTH",
    "price": 100,
    "volume": 110,
    "currency": "USD"
  }
]

Showing 3 of 240 elements.

config
{
  "closePartial": true,
  "initialTickSign": 1,
  "initialExpectedTicks": 24,
  "initialExpectedTickImbalance": 0.25,
  "alphaTicks": 0.2,
  "alphaTickImbalance": 0.2,
  "thresholdFloor": 4,
  "thresholdMultiplier": 1
}

Call

constructBars(trades, config)

Returns

array of 12 objects

[
  {
    "barIndex": 0,
    "session": "2026-01-05",
    "startTime": "2026-01-05T14:30:00.000Z",
    "endTime": "2026-01-05T14:33:18.000Z",
    "lastTradeTime": "2026-01-05T14:33:18.000Z",
    "open": 99.99,
    "high": 100.23,
    "low": 99.98,
    "close": 100.23,
    "volume": 5561,
    "dollarValue": 556664.98,
    "tickCount": 46,
    "firstTradeId": "T0001",
    "lastTradeId": "T0046"
  },
  {
    "barIndex": 1,
    "session": "2026-01-05",
    "startTime": "2026-01-05T14:33:25.000Z",
    "endTime": "2026-01-05T14:34:12.000Z",
    "lastTradeTime": "2026-01-05T14:34:12.000Z",
    "open": 100.22,
    "high": 100.35,
    "low": 100.22,
    "close": 100.35,
    "volume": 1353,
    "dollarValue": 135695.7,
    "tickCount": 11,
    "firstTradeId": "T0047",
    "lastTradeId": "T0057"
  },
  {
    "barIndex": 2,
    "session": "2026-01-05",
    "startTime": "2026-01-05T14:34:16.000Z",
    "endTime": "2026-01-05T14:34:58.000Z",
    "lastTradeTime": "2026-01-05T14:34:58.000Z",
    "open": 100.37,
    "high": 100.49,
    "low": 100.36,
    "close": 100.49,
    "volume": 1712,
    "dollarValue": 171902.93,
    "tickCount": 12,
    "firstTradeId": "T0058",
    "lastTradeId": "T0069"
  }
]

Showing 3 of 12 elements.

Diagrams

Tick-Imbalance Bars — article hero
Tick-Imbalance Bars — boundary and state
Tick-Imbalance Bars — construction anatomy

Calculation flow

Causal construction flow
flowchart TD
    A["Corrected, eligible, stably ordered trade"] --> B{"New session?"}
    B -->|Yes| C["Emit or drop tail; reset price, sign, and expectations"]
    B -->|No| D["Keep session state"]
    C --> E["Freeze threshold for new bar"]
    D --> F["Assign tick sign; flat carries prior sign"]
    E --> F
    F --> G["Update OHLCV and cumulative tick imbalance"]
    G --> H{"Absolute imbalance at least frozen threshold?"}
    H -->|No| A
    H -->|Yes| I["Emit complete bar and lineage"]
    I --> J["Update expected length and expected mean sign"]
    J --> E

How it works

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References