Skip to content

Trade Cross-Verification & Parity Protocol

Scope: Verification Gate between C# ATAS Indicators/Strategies and Python Backtesting
Key Scripts: recon.sh, Backtesting/scripts/reconcile_trades.py, Backtesting/scripts/reconcile_signals.py
Benchmark Suite: 6-Genome Recon 4 Suite (Backtesting/Reconciliations/)


🟢 Part 1: Layman & Trader Guide

1. What is Trade Cross-Verification?

Have you ever created an automated trading strategy that made money in backtesting, but lost money when turned on live?

This almost always happens because of implementation mismatch: the software running the backtest does not calculate things in the exact same way as the live trading platform.

In Trader-Jan, we solve this with a strict Bit-Perfect Parity Guarantee: every trade generated by the Python research engine must match the trade placed by the C# ATAS indicator down to the exact tick, timestamp, and penny.

2. "Why does my Chart HUD show slightly different stats than the Backtest?"

Traders often notice subtle differences between what is displayed on their chart HUD and the backtest output. Here is why: * Chart Data Window: The chart on your screen might only be loading 20 days of data, while your backtest is running over 180 days. * Session Boundaries & Timezones: The HUD calculates PnL relative to the visible bars on your screen, whereas the backtester evaluates strict CME session resets at 17:00 CT. * Real-Time Frontier: In live trading, the very last forming bar can fluctuate before closing. The backtester only registers signals after a bar has closed.

3. How Quality Assurance Works (The Verification Gate)

Before any new code, parameter change, or indicator update is approved: 1. We run the automated verification script (./recon.sh --summary). 2. The system simulates hundreds of trades across both C# ATAS exports and Python engines simultaneously. 3. If even a single trade enters 1 tick higher or exits 1 second off, the entire build is blocked.


💻 Part 2: Expert & Developer Specification

1. Parity Invariants & The Recon 4 Benchmark

To guarantee deterministic parity across different programming languages and runtime environments (.NET 8 vs Python/Numba), both platforms adhere to the Recon 4 Invariant Specification:

Parity Domain Invariant Rule
SL Priority If both $High_i \ge Target$ and $Low_i \le Stop$ on bar $i$, the trade must exit at Stop Loss.
Slippage Model Market orders incur $+1$ tick adverse execution on entry: $P_{\text{fill}} = Close_i \pm (\text{slippage} \times \text{TickSize})$.
Rollover Cutoff Daily session partitions occur at exactly 17:00:00.000 CT. Overnight open is 17:00:00.001 CT.
Breakeven Step Stop is adjusted when $High_i \ge EntryPrice + (\text{be_trigger} \times \text{TickSize})$. Adjusted price = $EntryPrice + (\text{be_offset} \times \text{TickSize})$.
Fill Delay Entries execute on bar $i+1$ Open or immediately upon bar $i$ Close completion.

2. Automated Reconciliation Harness (recon.sh)

The reconciliation pipeline matches trade logs generated from ATAS C# exports against Python engine output arrays:

graph LR
    subgraph ATAS C#
        Ind[Alpha / Options Signal] -->|Auto-Export| CSV[AccountStats_*.csv]
    end
    subgraph Python Engine
        MP[Master Parquet] --> BE[backtest_reversal.py]
        BE --> PTrades[Engine Trade Array]
    end
    CSV --> REC[reconcile_trades.py]
    PTrades --> REC
    REC --> Score{100% Bit-Perfect Match?}
    Score -->|Yes| Pass[GATE 2 APPROVED]
    Score -->|No| Fail[BUILD REJECTED: Show Tick Diffs]

3. 34-Column Reconciliation Schema

Both engines export trade records conforming to the unified schema:

TradeId,EntryBar,ExitBar,EntryTime,ExitTime,Direction,EntryPrice,ExitPrice,
Size,PnLTicks,PnLDollars,CumPnLTicks,ExitReason,MAE,MFE,DurationBars,
SessionDate,DayOfWeek,ATRAtEntry,SpreadAtEntry,SlippageTicks...

4. Continuous Integration Test Runners

  • ./Backtesting/run_tests.sh --parity: Runs unit-level signal math checks between C# test vectors and Python functions.
  • ./recon.sh --gid <GID>: Validates execution parity for a specific genome ID across historical Master Parquets.
  • ./recon.sh --all: Runs the entire 6-genome institutional benchmark suite.