Tick-Level Sense (v2.6+)¶
Reactive vs Anticipatory¶
The classic sense() uses volume spikes as a liquidity proxy:
Problem: volume is reactive — it is recorded after the bar closes, meaning the signal arrives too late.
With bid/ask data, STRATA uses spread widening instead:
Spread is anticipatory — market makers widen spreads before executing large orders, giving STRATA a leading indicator.
Auto-Detection¶
sense() automatically detects bid/ask — no code changes needed:
from strata import sense
# OHLCV only — uses volume proxy (reactive, as before)
candle = {"open": 150.0, "high": 151.2, "low": 149.5, "close": 150.8, "volume": 1_200_000}
signals = sense(window)
# signals["source"] == "volume"
# Add bid/ask — automatically uses spread (anticipatory)
candle["bid"] = 150.75
candle["ask"] = 150.85
signals = sense(window)
# signals["source"] == "spread"
# signals["liquidity_above"] reflects spread z-score, not volume
Spread Signal Formula¶
spread_ratio = (ask - bid) / mid_price # relative spread
avg_spread = mean(spread_ratios[-vol_period:]) # rolling average
std_spread = std(spread_ratios[-vol_period:]) # rolling std
z = (current_spread - avg_spread) / std_spread
liquidity_above = 1 - 1 / (1 + max(0, z)^1.5)
Mapping:
- z = 0 (normal spread) → liquidity_above = 0.0
- z = 2 (2σ above avg) → liquidity_above ≈ 0.73
- z = 4 (4σ above avg) → liquidity_above ≈ 0.98
Extended: sense_tick()¶
For full Level-2 data (bid/ask + order book sizes):
from strata import sense_tick
candle = {
"open": 150.0, "high": 150.5, "low": 149.8, "close": 150.2,
"volume": 1_000_000,
"bid": 150.18, "ask": 150.22,
"bid_size": 2500, # volume at best bid
"ask_size": 800, # volume at best ask
}
signals = sense_tick([...window..., candle])
Returns all standard signals plus:
| Signal | Range | Meaning |
|---|---|---|
spread_pressure |
[0, 1] | Current spread vs historical norm |
side_imbalance |
[-1, 1] | Order book pressure: +1=sell, -1=buy |
# bid-heavy (bid_size >> ask_size) → buy pressure → negative imbalance
signals["side_imbalance"] = -0.51 # buy pressure dominant
# ask-heavy (ask_size >> bid_size) → sell pressure → positive imbalance
signals["side_imbalance"] = +0.74 # sell pressure dominant
Effect on State Machine¶
Wide spread → elevated liquidity_above → higher trap_risk in STRATA-CORE:
spread_spike detected (z > 2σ)
→ liquidity_above = 0.73
→ update_state(): trap_risk increases
→ GUARD: may block LONG/SHORT if trap_risk > threshold
→ Final action: HOLD (conservative, avoiding the trap)
This happens before the price moves — anticipatory protection.