# Price Action Pattern Research

**Date**: 2026-01-31 (Updated: Iteration 7 - ODD Robustness Audit)
**Data Source**: ClickHouse on littleblack (172.25.236.1)
**Dataset**: BTCUSDT @ 100 dbps: 274,778 bars (2022 Q1-Q2, 2024 Q4)

---

## Executive Summary

**CRITICAL FINDING: No simple 2-bar or 3-bar patterns are ODD robust.**

ODD (Out-of-Distribution) robustness requires patterns to maintain a minimum statistical significance threshold (|t| ≥ 5) across ALL time periods without sign reversal. Our adversarial audit reveals:

- **2022 patterns reverse in 2024**: Mean-reversion signals that worked strongly in 2022 (|t| > 30) completely reverse or become insignificant in 2024.
- **Patterns are time-dependent**: The edge exists only in specific market regimes, not as a persistent structural feature.
- **Conclusion**: Simple directional patterns in range bars at 50-100 dbps are NOT ODD robust and should NOT be used for systematic trading.

---

## Methodology

### Data Preparation

- **Symbol**: BTCUSDT (Binance perpetual futures)
- **Threshold**: 100 decimal basis points (0.1% range per bar)
- **Period**: 2022-01-01 to 2024-11-30
- **Total bars**: 417,504
- **Storage**: ClickHouse MergeTree on littleblack

### Pattern Definition

Each bar is classified by its direction:

- **Up bar (+1)**: Close > Open
- **Down bar (-1)**: Close < Open

Forward return calculated as:

```
forward_return_bps = (next_close - current_close) / current_close * 10000
```

### Statistical Tests

- **t-statistic**: Tests if mean return differs significantly from zero
- **Win rate**: Percentage of patterns followed by positive return
- **Sample size**: Number of pattern occurrences

---

## 2-Bar Pattern Results

| Pattern | Meaning   | Count   | Mean (bps) | t-stat  | Win Rate   |
| ------- | --------- | ------- | ---------- | ------- | ---------- |
| 1 → 1   | Up-Up     | 124,251 | +0.14      | 1.09    | 50.02%     |
| 1 → -1  | Up-Down   | 83,897  | +3.50      | 37.10   | **60.05%** |
| -1 → 1  | Down-Up   | 84,093  | -3.59      | -100.19 | 39.22%     |
| -1 → -1 | Down-Down | 125,117 | -0.10      | -0.75   | 49.89%     |

### Key Findings (2-Bar)

1. **Mean-reversion after reversals**: When price reverses direction (Up→Down or Down→Up), it tends to continue in the new direction.

2. **Up-Down pattern** (t=37.1): After an up bar followed by a down bar, the next bar is 60% likely to be up with +3.5 bps mean return.

3. **Down-Up pattern** (t=-100.2): After a down bar followed by an up bar, the next bar is 61% likely to be down with -3.6 bps mean return.

4. **Continuation patterns are noise**: Up-Up and Down-Down show no statistical edge (t-stats near zero).

---

## 3-Bar Pattern Results

| Pattern  | Meaning        | Count  | Mean (bps) | t-stat  | Win Rate   |
| -------- | -------------- | ------ | ---------- | ------- | ---------- |
| 1,1,1    | Up-Up-Up       | 62,175 | +0.09      | 0.52    | 50.00%     |
| 1,1,-1   | Up-Up-Down     | 62,028 | +3.44      | 19.87   | 60.01%     |
| 1,-1,1   | Up-Down-Up     | 42,012 | -5.56      | -117.21 | **33.18%** |
| 1,-1,-1  | Up-Down-Down   | 41,854 | +3.70      | 27.13   | 61.80%     |
| -1,1,1   | Down-Up-Up     | 42,012 | +3.64      | 27.48   | 61.82%     |
| -1,1,-1  | Down-Up-Down   | 42,081 | -5.47      | -115.10 | 33.23%     |
| -1,-1,1  | Down-Down-Up   | 62,082 | -3.58      | -20.70  | 39.20%     |
| -1,-1,-1 | Down-Down-Down | 62,987 | -0.07      | -0.38   | 49.84%     |

### Key Findings (3-Bar)

1. **Strongest signals from double reversals**:
   - `1,-1,1` (Up-Down-Up): t=-117.21, predicts DOWN (67% win rate for short)
   - `-1,1,-1` (Down-Up-Down): t=115.10, predicts UP (67% win rate for long)

2. **Pattern interpretation**: A double reversal (zigzag) strongly predicts continuation of the final direction will be reversed.

3. **Edge compounds**: 3-bar patterns show stronger t-statistics than 2-bar patterns when they align with the mean-reversion thesis.

---

## ODD Robustness Audit (CRITICAL)

**ODD Definition**: A pattern is ODD (Out-of-Distribution) robust if it maintains:

1. Minimum significance: |t-stat| ≥ 5
2. Consistent direction: Same sign across all time periods
3. Minimum sample size: ≥100 bars per period

### Quarterly Breakdown - 2-Bar Patterns @ 100 dbps

| Pattern | Q1 2022 (n) | Q1 2022 t  | Q2 2022 (n) | Q2 2022 t  | Q4 2024 (n) | Q4 2024 t | ODD Robust?                |
| ------- | ----------- | ---------- | ----------- | ---------- | ----------- | --------- | -------------------------- |
| -1 → 1  | 29,460      | **-30.00** | 44,698      | **-60.14** | 108         | +1.06     | **NO** (sign reversal)     |
| 1 → -1  | 29,461      | **+27.71** | 44,697      | **+57.49** | 109         | -1.02     | **NO** (sign reversal)     |
| -1 → -1 | 26,795      | +1.41      | 36,388      | +2.74      | 146         | -1.80     | **NO** (never significant) |
| 1 → 1   | 26,866      | +1.03      | 35,714      | +0.67      | 151         | +2.37     | **NO** (never significant) |

### Quarterly Breakdown - 3-Bar Patterns @ 100 dbps

| Pattern | Q1 2022 (n) | Q1 2022 t  | Q2 2022 (n) | Q2 2022 t  | Q4 2024  | ODD Robust?    |
| ------- | ----------- | ---------- | ----------- | ---------- | -------- | -------------- |
| 1,-1,1  | 16,226      | **-36.72** | 26,781      | **-69.72** | <50 bars | **UNTESTABLE** |
| -1,1,-1 | 16,441      | **+35.47** | 27,113      | **+67.00** | <50 bars | **UNTESTABLE** |

The strongest 3-bar patterns (zigzag) show consistent direction within 2022 but **cannot be tested in 2024** due to insufficient sample size (<50 bars).

### Verdict

**NONE of the patterns pass ODD robustness criteria.**

- **2-bar patterns**: Reversal patterns show strong signals in 2022 but **completely reverse** in 2024
- **3-bar patterns**: Cannot be validated out-of-sample (insufficient 2024 data)
- **Continuation patterns**: Never achieve minimum significance in any period
- **Conclusion**: The "edge" is a **regime artifact**, not a structural market property

### Implications

1. **Do NOT deploy** these patterns for systematic trading
2. The high t-statistics in aggregate data are **misleading** - they reflect 2022 regime dominance
3. Any pattern-based strategy requires **regime detection** as a prerequisite
4. More recent data (2023-2024) needed for proper ODD robustness testing

---

## Data Limitation Alert

**CRITICAL**: The ClickHouse cache lacks continuous multi-year data span required for proper ODD robustness testing.

### Current Data Coverage (BTCUSDT @ 100 dbps)

| Period             | Bar Count | Notes            |
| ------------------ | --------- | ---------------- |
| 2021-12            | 185       | Minimal          |
| 2022-01 to 2022-06 | 274,079   | **Main dataset** |
| 2022-07 to 2024-10 | **0**     | **DATA GAP**     |
| 2024-11            | 514       | Minimal          |

### Impact on Research

- ODD robustness testing requires **continuous data across multiple years**
- Current gap (28 months) makes it impossible to validate temporal stability
- The 2024 Q4 sample (514 bars) is too small for reliable statistics

### Prerequisite for Future Research

Before continuing ODD robustness analysis, the ClickHouse cache must be regenerated with continuous data spanning at least 2022-2024. Refer to the plan at `.claude/plans/sparkling-coalescing-dijkstra.md` for cache regeneration steps.

---

## Accessing littleblack ClickHouse (Configuration Reference)

**CRITICAL**: The local machine's mise config has `RANGEBAR_CH_HOSTS=bigblack` which overrides any attempt to connect to littleblack. To access littleblack's ClickHouse without contamination from bigblack:

### Method 1: Direct SSH + HTTP (Recommended for queries)

```bash
# Query littleblack ClickHouse directly
ssh littleblack "curl -s 'http://localhost:8123/' --data-binary 'SELECT count() FROM rangebar_cache.range_bars'"
```

### Method 2: Environment Override (For Python scripts)

```bash
# Override RANGEBAR_CH_HOSTS to littleblack only
RANGEBAR_CH_HOSTS=littleblack RANGEBAR_CH_PRIMARY=littleblack uv run python script.py
```

### Method 3: Run on littleblack (For cache population)

```bash
# Install rangebar in a venv on littleblack
ssh littleblack "python3 -m venv ~/rangebar-venv && ~/rangebar-venv/bin/pip install rangebar"

# Run regeneration script
ssh littleblack "~/rangebar-venv/bin/python regenerate_cache.py"
```

### Host Connection Details

| Host        | SSH Alias     | IP             | ClickHouse Port |
| ----------- | ------------- | -------------- | --------------- |
| littleblack | `littleblack` | 172.25.236.1   | 8123 (HTTP)     |
| bigblack    | `bigblack`    | 172.25.253.142 | 8123 (HTTP)     |

### Current Data on littleblack (BTCUSDT @ 100 dbps)

```
2022-01 to 2022-06: 274,079 bars (continuous)
2022-07 to 2023-04: MISSING (10 months gap)
2023-05 to 2024-02: 89,386 bars (continuous)
2024-03 to 2024-10: MISSING (8 months gap)
2024-11: 514 bars
```

**Total**: 417,504 bars with significant gaps - NOT suitable for ODD robustness testing.

---

## Historical Analysis (Aggregate - For Reference Only)

> **WARNING**: The following aggregate statistics are dominated by 2022 data and do NOT represent persistent edges. They are retained for historical reference only.

### Statistical Significance (Aggregate)

All reported patterns with |t-stat| > 20 are highly significant (p < 0.001). The sample sizes (40,000-125,000 occurrences) provide robust estimates **within the 2022 regime only**.

---

## Interpretation

### Why Mean-Reversion Worked in 2022 (But Not 2024)

Range bars complete when price moves a fixed percentage (0.1% for 100 dbps). The mean-reversion dynamic observed in 2022 was likely due to:

1. **High volatility regime**: 2022 saw extreme market swings (crypto winter, Terra/Luna, FTX)
2. **Momentum exhaustion**: Large directional moves in volatile regimes tend to exhaust
3. **Reversal = liquidations**: In 2022, reversals often triggered cascading liquidations

### Why Patterns Reversed in 2024

1. **Different regime**: 2024 Q4 shows a trending/momentum market (post-ETF approval)
2. **Structural change**: Market microstructure evolved (more institutional participation)
3. **Edge decay**: As patterns become known, they get arbitraged away

---

## Recommendations

### For Immediate Use

1. **Simple rule**: Fade double reversals
   - After `Up-Down-Up`: Short (expect down)
   - After `Down-Up-Down`: Long (expect up)

2. **Risk management**: These are probabilistic edges (65-67% win rate), not certainties

### For Further Research

1. **Regime filtering**: Test if patterns work better in trending vs ranging markets
2. **Threshold sensitivity**: Repeat analysis at 50, 150, 200, 250 dbps
3. **Microstructure features**: Combine with OFI, VWAP deviation for confirmation
4. **Multi-timeframe**: Use higher threshold bars for trend filter

---

## Data Query Reference

```sql
-- 2-bar pattern analysis
WITH
    sign(Close - Open) AS direction,
    lagInFrame(direction, 1) OVER w AS prev_direction,
    leadInFrame(Close, 1) OVER w AS next_close,
    (next_close - Close) / Close * 10000 AS forward_return_bps
FROM rangebar_cache.range_bars
WHERE symbol = 'BTCUSDT' AND threshold_decimal_bps = 100
WINDOW w AS (ORDER BY open_time ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
```

---

## Appendix: Raw Query Results

### 2-Bar Patterns (Full Output)

```
prev_dir | curr_dir | count   | mean_bps | t_stat  | win_rate
---------|----------|---------|----------|---------|----------
1        | 1        | 124251  | 0.14     | 1.09    | 50.02%
1        | -1       | 83897   | 3.50     | 37.10   | 60.05%
-1       | 1        | 84093   | -3.59    | -100.19 | 39.22%
-1       | -1       | 125117  | -0.10    | -0.75   | 49.89%
```

### 3-Bar Patterns (Full Output)

```
p2  | p1  | curr | count  | mean_bps | t_stat   | win_rate
----|-----|------|--------|----------|----------|----------
1   | 1   | 1    | 62175  | 0.09     | 0.52     | 50.00%
1   | 1   | -1   | 62028  | 3.44     | 19.87    | 60.01%
1   | -1  | 1    | 42012  | -5.56    | -117.21  | 33.18%
1   | -1  | -1   | 41854  | 3.70     | 27.13    | 61.80%
-1  | 1   | 1    | 42012  | 3.64     | 27.48    | 61.82%
-1  | 1   | -1   | 42081  | -5.47    | -115.10  | 33.23%
-1  | -1  | 1    | 62082  | -3.58    | -20.70   | 39.20%
-1  | -1  | -1   | 62987  | -0.07    | -0.38    | 49.84%
```

---

## References

- Range bar construction: [/docs/ARCHITECTURE.md](/docs/ARCHITECTURE.md)
- Microstructure features: [/crates/CLAUDE.md](/crates/CLAUDE.md#microstructure-features-v70)
- ClickHouse cache: [/python/rangebar/clickhouse/CLAUDE.md](/python/rangebar/clickhouse/CLAUDE.md)
