# Order Flow Analysis

> A Claude skill from brainbytes-dev/everything-claude-trading.

- **Type:** Skill
- **Install:** `agentstack add skill-brainbytes-dev-everything-claude-trading-order-flow-analysis`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [brainbytes-dev](https://agentstack.voostack.com/s/brainbytes-dev)
- **Installs:** 0
- **Category:** [Finance & Payments](https://agentstack.voostack.com/c/finance-and-payments)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [brainbytes-dev](https://github.com/brainbytes-dev)
- **Source:** https://github.com/brainbytes-dev/everything-claude-trading/tree/main/skills/execution/order-flow-analysis

## Install

```sh
agentstack add skill-brainbytes-dev-everything-claude-trading-order-flow-analysis
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Order Flow Analysis

> Order flow analysis — volume profile, footprint charts, delta for short-term price prediction.

## When to Activate

- User is analyzing intraday order flow for trading signals
- Building volume profile analysis (POC, value area, single prints)
- Using cumulative delta and footprint charts for directional bias
- Identifying aggressor imbalances and absorption patterns
- Predicting short-term price moves from order flow data

## Core Concepts

### What Is Order Flow?

Order flow is the stream of actual buy and sell transactions hitting the market. Unlike price charts, which show outcomes, order flow reveals the process — who is aggressive, where liquidity rests, and where price is accepted or rejected.

Key distinction:
- **Passive orders**: limit orders resting on the book (provide liquidity)
- **Aggressive orders**: market orders or marketable limit orders that cross the spread (take liquidity)

Price moves when aggressive demand exceeds passive supply (or vice versa). Order flow analysis identifies these imbalances in real time.

### Volume Profile

Volume profile shows the distribution of traded volume at each price level over a defined period:

- **Point of Control (POC)**: the price level with the highest traded volume — acts as a magnet
- **Value Area (VA)**: the price range containing 70% of total volume (one standard deviation)
- **Value Area High (VAH)**: upper boundary of the value area — resistance
- **Value Area Low (VAL)**: lower boundary — support
- **High Volume Nodes (HVN)**: prices with concentrated volume — acceptance zones, tend to attract price
- **Low Volume Nodes (LVN)**: prices with thin volume — rejection zones, price moves quickly through these

### Cumulative Delta

Delta = volume traded at the ask (buyer-initiated) minus volume traded at the bid (seller-initiated):

```
Delta = Ask Volume - Bid Volume
```

- **Positive delta**: net buying pressure
- **Negative delta**: net selling pressure
- **Cumulative delta**: running sum of delta over time

Divergences between cumulative delta and price are powerful signals:
- Price rising + delta falling = buying exhaustion (bearish divergence)
- Price falling + delta rising = selling exhaustion (bullish divergence)

### Footprint Charts

Footprint charts (also called order flow charts) show bid/ask volume at each price level within each candle:

```
Price   Bid Vol x Ask Vol
150.05   1200  x  3500    ← aggressive buying
150.00   2800  x  2900    ← balanced
149.95   4100  x  1500    ← aggressive selling
149.90   3200  x  800     ← aggressive selling
```

Imbalance ratios (ask/bid at each price) reveal where aggressive participants dominate.

## Methodology

### Step 1: Classify Trade Direction

```python
import pandas as pd
import numpy as np

def classify_trades_tick_rule(trades):
    """
    Tick rule: classify trades as buyer/seller initiated.
    - Trade at higher price than previous = buyer-initiated
    - Trade at lower price than previous = seller-initiated
    - Same price = use previous classification
    """
    trades = trades.copy()
    trades['price_change'] = trades['price'].diff()

    trades['direction'] = 0  # 0 = unknown
    trades.loc[trades['price_change'] > 0, 'direction'] = 1   # uptick = buy
    trades.loc[trades['price_change']  merged['midpoint'], 'direction'] = 1
    merged.loc[merged['price']  0 else 0

        if vol_above >= vol_below:
            va_high = prices_sorted[high_idx + 1]
            va_volume += vol_above
        else:
            va_low = prices_sorted[low_idx - 1]
            va_volume += vol_below

    return {
        'profile': profile,
        'poc': poc,
        'vah': va_high,
        'val': va_low,
        'total_volume': total_vol,
    }
```

### Step 3: Footprint Chart Analysis

```python
def build_footprint(trades, bar_interval='5min', tick_size=0.01):
    """
    Build footprint (bid x ask at each price) for each time bar.
    """
    trades['bar'] = trades['timestamp'].dt.floor(bar_interval)
    trades['price_level'] = (trades['price'] / tick_size).round() * tick_size

    footprint = trades.groupby(['bar', 'price_level']).agg(
        bid_vol=('sell_volume', 'sum'),
        ask_vol=('buy_volume', 'sum'),
        total_vol=('size', 'sum'),
    )

    footprint['delta'] = footprint['ask_vol'] - footprint['bid_vol']
    footprint['imbalance_ratio'] = footprint['ask_vol'] / footprint['bid_vol'].clip(lower=1)

    return footprint

def detect_imbalances(footprint, imbalance_threshold=3.0):
    """
    Flag price levels with significant buyer/seller imbalance.
    Imbalance ratio > 3 = strong aggressor dominance at that price.
    """
    footprint['buy_imbalance'] = footprint['imbalance_ratio'] > imbalance_threshold
    footprint['sell_imbalance'] = (1 / footprint['imbalance_ratio']) > imbalance_threshold

    # Stacked imbalances: 3+ consecutive prices with buy imbalance = strong demand
    # These often indicate institutional buying
    return footprint
```

### Step 4: Cumulative Delta Analysis

```python
def cumulative_delta(trades, interval='1min'):
    """
    Compute cumulative delta over time intervals.
    """
    trades['interval'] = trades['timestamp'].dt.floor(interval)

    delta_series = trades.groupby('interval').apply(
        lambda g: g['buy_volume'].sum() - g['sell_volume'].sum()
    )

    cum_delta = delta_series.cumsum()

    return cum_delta

def delta_divergence(price_series, cum_delta, lookback=20):
    """
    Detect divergences between price and cumulative delta.

    Bearish divergence: price makes new high but cum_delta doesn't
    Bullish divergence: price makes new low but cum_delta doesn't
    """
    price_high = price_series.rolling(lookback).max()
    delta_at_price_high = cum_delta[price_series == price_high]

    # If price is at new high but delta is below its previous value at the last high
    # → bearish divergence (buyers are weakening)

    divergences = []
    highs = price_series[price_series == price_high].index
    for i in range(1, len(highs)):
        if cum_delta[highs[i]]  avg_vol * volume_threshold:
                # Heavy selling at this level
                next_bar_low = get_next_bar_low(bar)
                if next_bar_low >= price_level:
                    # Price held despite selling = buy absorption
                    yield {
                        'time': bar, 'price': price_level,
                        'type': 'buy_absorption',
                        'volume': row['bid_vol'],
                        'signal': 'bullish'
                    }
```

## Examples

### Intraday Trading with Volume Profile

```python
# Yesterday's profile
yesterday = build_volume_profile(yesterday_trades)
# POC at 4150, VAH at 4165, VAL at 4135

# Today's opening:
# If price opens above VAH (4165) = bullish breakout (look for long entries)
# If price opens below VAL (4135) = bearish breakout (look for short entries)
# If price opens inside VA = expect rotation between VAH and VAL

# POC as magnet: if price moves away from POC on low volume,
# expect a return to POC
```

### Real-Time Delta for Execution

```python
# Use delta to time entries within an algo execution window:
# If you need to buy and delta is negative (sellers aggressive),
# place patient limit orders — supply is available
# If delta turns strongly positive, consider crossing spread
# before buyers push price higher
```

## Quality Gate

- [ ] Trade classification method documented (tick rule, quote rule, or Lee-Ready)
- [ ] Volume profile uses appropriate time period (session, multi-day, or developing profile)
- [ ] Value area calculated correctly (70% of volume, expanding from POC)
- [ ] Delta calculation handles trades at midpoint correctly
- [ ] Footprint imbalance thresholds calibrated to the specific instrument
- [ ] Divergence signals confirmed with price action (divergence alone is not a trade signal)
- [ ] Absorption detection accounts for hidden orders and iceberg refills
- [ ] Latency of data feed adequate for the trading timeframe
- [ ] Data excludes off-exchange prints, block trades, and other non-informative volume
- [ ] Backtested edge of order flow signals accounts for realistic execution delays

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [brainbytes-dev](https://github.com/brainbytes-dev)
- **Source:** [brainbytes-dev/everything-claude-trading](https://github.com/brainbytes-dev/everything-claude-trading)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-brainbytes-dev-everything-claude-trading-order-flow-analysis
- Seller: https://agentstack.voostack.com/s/brainbytes-dev
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
