bugsDebugging a Strategy (Using Order History)

This guide shows how to use order-level data to diagnose why a strategy behaves the way it does, and how to fix it without guessing.


Why Order History Matters

Aggregate metrics (PnL, win rate, drawdown) tell you what happened. Order history tells you why it happened.

Order history exposes:

  • When trades fired

  • What triggered them

  • How frequently logic re-evaluates

  • Whether exits are intentional or accidental

If you don’t inspect order history, you’re debugging blind.


Step 1: Validate That Logic Fires Where You Expect

What to check

  • Do buys and sells occur near obvious signal points?

  • Are trades clustered around indicator crossings or thresholds?

Common failure

  • Trades fire too early or too late

Likely causes

  • Indicator periods too short or too long

  • Using Compare when Crossover was intended

  • Multiple evaluations per bar causing duplicate triggers

Fixes

  • Replace threshold logic with crossover logic

  • Increase lookback periods

  • Add explicit exit conditions


Step 2: Look for Overtrading

Symptoms in order history

  • Many small trades close together

  • Rapid buy–sell–buy sequences

  • High trade count with flat or negative PnL

Likely causes

  • Conditions oscillating around a threshold

  • No cooldown or state awareness

  • Missing exit filters

Fixes

  • Add confirmation logic using AND

  • Widen thresholds (e.g., RSI < 28 instead of < 30)

  • Add alternative exits with OR to avoid churn


Step 3: Identify Unintended Re-Entries

Symptoms

  • Strategy re-enters immediately after exiting

  • Back-to-back identical trades

Likely causes

  • Entry condition remains true after exit

  • Exit does not invalidate the entry condition

Fixes

  • Add a separate exit condition that explicitly flips the signal

  • Use a crossover instead of a static comparison

  • Introduce a second condition to gate re-entry


Step 4: Diagnose Large Drawdowns

Symptoms

  • A few large losses dominate PnL

  • Drawdowns occur during sharp moves or events

Order history clues

  • Trades entered late into moves

  • Exits lag reversals

  • Positions held through regime shifts

Likely causes

  • Trend-following logic without risk exits

  • Mean-reversion logic in trending regimes

  • No stop-loss or profit-taking logic

Fixes

  • Add protective exits (stop-loss or time-based exit)

  • Add a regime filter (e.g., trend confirmation)

  • Reduce position size before changing logic


Step 5: Compare Entry Quality vs Exit Quality

How to tell

  • Plot order markers on price

  • Visually inspect entry timing vs exit timing

Patterns

  • Good entries, bad exits → profits given back

  • Bad entries, good exits → churn and noise

Fixes

  • If exits are weak:

    • Add explicit profit-taking logic

    • Exit on signal invalidation, not just reversal

  • If entries are weak:

    • Add confirmation indicators

    • Delay entry using crossovers instead of thresholds


Step 6: Detect Logic That Only Works in One Regime

Symptoms

  • Strategy performs well in one market

  • Fails catastrophically in others

Order history clues

  • Trades cluster in specific market conditions

  • Long inactive periods followed by bursts

Likely causes

  • Strategy implicitly assumes:

    • High liquidity

    • Smooth trends

    • Frequent oscillation

Fixes

  • Test across multiple markets

  • Add regime-dependent conditions

  • Accept that some strategies are intentionally narrow


Step 7: Use “What Didn’t Trade” as a Signal

Sometimes the bug is silence.

Symptoms

  • Very few or zero trades

  • Strategy appears inert

Likely causes

  • Over-constrained logic

  • Conflicting conditions

  • AND gate requiring incompatible signals

Fixes

  • Temporarily remove conditions

  • Test each condition independently

  • Replace AND with OR to diagnose conflicts


Common Debugging Patterns

Symptom
Likely Issue
Fix

Too many trades

Threshold noise

Add crossover or confirmation

Large drawdowns

Missing risk exits

Add stop-loss / invalidation

Instant re-entry

Entry not invalidated

Add exit filter

Works once, then fails

Regime dependence

Add regime filter

No trades

Over-constrained logic

Simplify conditions


Debugging Mindset

  • Change one thing at a time

  • Use order history before changing parameters

  • Assume the strategy is wrong, not the market

A strategy that fails loudly is a gift—it tells you exactly what assumption broke.

PredictBack is built to make those failures visible.

Last updated