docs: Document ADX-based trailing stop multiplier system

Added comprehensive documentation for Nov 19, 2025 enhancement:

Architecture Overview:
- Updated Exit Strategy section with ADX multiplier details
- Documented graduated system (>30: 1.5, 25-30: 1.25×, <25: 1.0×)
- Explained profit acceleration (>2%: 1.3× additional)
- Noted backward compatibility (trades without ADX use base)

Position Manager Section:
- Added detailed ADX multiplier calculation logic
- Documented combined effect examples (ADX 29.3 + 2% profit = 1.95×)
- Explained purpose (capture more of 38% MFE trades)
- Noted trail distance clamping for safety

When Making Changes Section:
- Added item #11 for trailing stop modifications
- Documented verification logs to watch for
- Listed ActiveTrade interface requirement (adxAtEntry field)
- Included example log output for validation

Related commit: d09838d (implementation)
This commit is contained in:
mindesbunister
2025-11-19 12:03:06 +01:00
parent d09838d1dc
commit 6515e1054b

View File

@@ -50,8 +50,18 @@
- Safety bounds: MIN/MAX caps prevent extremes
- Falls back to fixed % if ATR unavailable
- **Runner:** 40% remaining after TP1 (configurable via `TAKE_PROFIT_1_SIZE_PERCENT=60`)
- **Trailing Stop:** ATR-based (1.3-1.5x ATR multiplier), activates after TP2 trigger
- **Benefits:** Regime-agnostic (adapts to bull/bear automatically), asset-agnostic (SOL vs BTC different ATR)
- **Trailing Stop:** ATR-based with ADX multiplier (Nov 19, 2025 enhancement):
- Base: ATR × 1.5 multiplier
- **ADX-based widening (graduated):**
- ADX > 30: 1.5× multiplier (very strong trends)
- ADX 25-30: 1.25× multiplier (strong trends)
- ADX < 25: 1.0× multiplier (base trail, weak/moderate trends)
- **Profit acceleration:** Profit > 2%: additional 1.3× multiplier
- **Combined effect:** ADX 29.3 + 2% profit = trail multiplier 1.5 × 1.3 = 1.95×
- **Purpose:** Capture more of massive trend moves (e.g., 38% MFE trades)
- **Backward compatible:** Trades without ADX use base 1.5× multiplier
- Activates after TP2 trigger
- **Benefits:** Regime-agnostic (adapts to bull/bear automatically), asset-agnostic (SOL vs BTC different ATR), trend-strength adaptive (wider trail for strong trends)
- **Note:** All UI displays dynamically calculate runner% as `100 - TAKE_PROFIT_1_SIZE_PERCENT`
**Per-Symbol Configuration:** SOL and ETH have independent enable/disable toggles and position sizing:
@@ -491,7 +501,17 @@ await positionManager.addTrade(activeTrade)
- **TP2-as-Runner system**: TP1 (configurable %, default 75%) → TP2 trigger (no close, activate trailing) → Runner (remaining %) with ATR-based trailing stop
- Dynamic SL adjustments: Moves to breakeven after TP1, locks profit at +1.2%
- **On-chain order synchronization:** After TP1 hits, calls `cancelAllOrders()` then `placeExitOrders()` with updated SL price at breakeven (uses `retryWithBackoff()` for rate limit handling)
- **ATR-based trailing stop:** Calculates trail distance as `(atrAtEntry / currentPrice × 100) × trailingStopAtrMultiplier`, clamped between min/max %
- **ATR-based trailing stop with ADX multiplier (Nov 19, 2025):**
- Base calculation: `(atrAtEntry / currentPrice × 100) × trailingStopAtrMultiplier`
- **ADX-based widening:** Multiplier adjusted based on trend strength at entry
- `trade.adxAtEntry > 30`: Apply 1.5× multiplier (very strong trends)
- `trade.adxAtEntry 25-30`: Apply 1.25× multiplier (strong trends)
- `trade.adxAtEntry < 25`: Apply 1.0× multiplier (base trail)
- **Profit acceleration:** If current profit > 2%, apply additional 1.3× multiplier
- **Combined effect:** ADX 29.3 + 2% profit = 1.5 × 1.3 = 1.95× total multiplier
- **Purpose:** Capture more profit on massive trend moves (e.g., 38% MFE trades)
- **Backward compatible:** Trades without `adxAtEntry` use base multiplier
- Trail distance clamped between min/max % for safety
- Trailing stop: Activates when TP2 price hit, tracks `peakPrice` and trails dynamically
- Closes positions via `closePosition()` market orders when targets hit
- Acts as backup if on-chain orders don't fill
@@ -2654,7 +2674,15 @@ if (!enabled) {
- Verify TP1 hit → 75% close → SL moved to breakeven
- SQL: Check `tp1Hit`, `slMovedToBreakeven`, `currentSize` in Trade table
- Compare: Position Manager logs vs actual Drift position size
10. **Calculation changes:** Add verbose logging and verify with SQL
- **ADX multiplier verification:** Watch for "Strong trend (ADX X): Trail multiplier..." messages
11. **Trailing stop changes:**
- ADX multiplier logic in Position Manager (lines 1210-1243)
- Requires `adxAtEntry` field in ActiveTrade interface
- Test with known ADX values to verify graduated multipliers (>30: 1.5×, 25-30: 1.25×, <25: 1.0×)
- Profit acceleration: >2% profit adds 1.3× multiplier
- Log shows: `Strong trend (ADX 29.3): Trail multiplier 1.5x → 1.88x (profit acceleration applied)`
- Backward compatible: Trades without ADX use base multiplier
12. **Calculation changes:** Add verbose logging and verify with SQL
- Log every intermediate step, especially unit conversions
- Never assume SDK data format - log raw values to verify
- SQL query with manual calculation to compare results