Skip to content

Bug: Target detection missing setup bar as first target for reversal signals #37

@jlixfeld

Description

@jlixfeld

Problem

The target detection logic in _detect_targets_for_signal() may skip the setup bar (the bar being broken) as the first target for reversal signals. The setup bar's high (for long signals) or low (for short signals) should ALWAYS be the first element in the target_prices list.

Current Behavior

The ladder-building logic scans historical prices and applies trigger bar filtering:

  • Skips the trigger bar (i=0 in reversed list)
  • Starts evaluating targets from i=1 (setup bar)
  • May reject setup bar if its price doesn't exceed trigger bar price

Example - 2D-2U Long Reversal:

  • Bar 8: Setup bar (2D) - high should be first target
  • Bar 9: Trigger bar (2U) - used for filtering, not a target
  • Bar 10: Signal bar - where pattern detected

If setup bar high ≤ trigger bar high, the ladder logic may skip it, resulting in an empty or incomplete target list.

Expected Behavior

Setup bar should ALWAYS be first target for reversals:

# For 2D-2U (long reversal)
setup_bar_high = 510.01  # Bar 8
trigger_bar_high = 513.94  # Bar 9

# Expected target_prices:
[510.01, 512.48, 514.59, ...]  # Setup bar high is target_prices[0]

# Setup bar is what's being broken - must be first target

Impact

  • Traders missing the first (most important) target level
  • Risk/reward calculations based on incorrect first target
  • Target ladders incomplete or starting from wrong level
  • Affects ALL reversal signals (2D-2U, 2U-2D, 3-bar reversals, etc.)

Root Cause

thestrat/indicators.py lines 984-1014:

  • Logic builds ladder from historical data
  • Setup bar treated like any other historical bar
  • Ladder filtering may reject setup bar

Solution Approach

  1. Phase 1-4: Establish clear terminology with visual diagrams (IN PROGRESS)
  2. Phase 5: Update _detect_targets_for_signal() to:
    • Always include setup bar as first target for reversals
    • Then apply ladder logic for additional historical targets
    • Maintain trigger bar filtering and bound trimming
  3. Phase 6-7: Remove obsolete test, add 7 comprehensive tests
  4. Phase 8-11: Update docs, test, commit, PR

Related Files

  • thestrat/indicators.py - _detect_targets_for_signal() method
  • docs/user-guide/pattern-terminology.md - New terminology doc (creating)
  • tests/test_u_indicators.py - Test coverage (will add comprehensive tests)

Branch

fix/target-detection-setup-bar (creating next)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghigh-priorityCritical issue requiring immediate attention

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions