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
- Phase 1-4: Establish clear terminology with visual diagrams (IN PROGRESS)
- 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
- Phase 6-7: Remove obsolete test, add 7 comprehensive tests
- 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)
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 thetarget_priceslist.Current Behavior
The ladder-building logic scans historical prices and applies trigger bar filtering:
Example - 2D-2U Long Reversal:
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:
Impact
Root Cause
thestrat/indicators.pylines 984-1014:Solution Approach
_detect_targets_for_signal()to:Related Files
thestrat/indicators.py-_detect_targets_for_signal()methoddocs/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)