🕰️Updates

This section covers both the refined edge-case handling already added, as well as future enhancements aimed at strengthening the backtest parser’s capabilities.

Edge Cases and Improvements

  1. Wick vs. Body Consideration

    • Bullish/Bearish Recognition: The algorithm checks if a candle is bullish (close > open) or bearish (close < open).

    • Stop Loss or Take Profit Proximity: Determines how close the close price is to these levels.

    • Candle Range: Looks at the relative size of the movement in both directions (high and low).

    • Why It Matters: This approach helps decide which level was likely hit first in a candle that reaches both stop loss and take profit.

  2. Time-Based Priority

    • Issue: OHLC data doesn’t show intrabar price paths; the sequence of price movements within a candle is lost.

    • Potential Improvement: A probabilistic model that simulates the possible sequence of price movement during each candle could enhance the accuracy of detecting SL/TP hits.

  3. Slippage and Execution Delay

    • Current Approach: Slippage is accounted for by adjusting the exit price.

    • Additional Factors:

      • Execution Delay: Fast markets can move the price further by the time an order actually executes.

      • Volatility-Based Slippage: High volatility can lead to bigger slippage, so you could scale your slippage assumptions based on market conditions.

  4. Gap Openings

    • Issue: Gaps between candles (e.g., overnight gaps) can cause exits to occur far from the intended SL/TP.

    • Potential Improvement: Detect and handle gaps to adjust exit prices so they reflect the real market open level.


Future Enhancements for Parser

These planned features will further improve the realism and flexibility of the backtest parser by incorporating trailing stops and partial exits.

1. Trailing Stops

What It Is A dynamic stop-loss level that “trails” the price when it moves in favor of a trade, helping lock in profits.

Implementation Plan

  • Data Structure Updates

    • initialStopLoss, trailingStopActive, trailingStopLevel, trailingStopDistance

  • Activation Logic

    • Rules for when trailing stops activate (e.g., after X% gain).

    • Continually update the trailing stop level as price moves up/down.

  • Exit Detection

    • Switch from using the initial SL to the trailing stop level once active.

    • Track whether a trade exited via trailing stop vs. initial SL.

  • Statistics

    • Compare performance with and without trailing stops.

    • Track how many trades used trailing stops and their success rates.

  • Configuration

    • User option to enable/disable trailing stops.

    • Configure trailing distance and activation thresholds.

2. Partial Exits

What It Is Allows you to exit part of a position early (partial take profit) while leaving some portion open to capture bigger moves.

Implementation Plan

  • Data Structure Updates

    • remainingPositionSize, partialExits[], averageExitPrice

  • Exit Logic

    • Close a percentage of the position at the first TP level.

    • Let the rest target additional TP levels.

    • Calculate weighted average exit price across all partial exits.

  • Risk Management

    • Optional move to breakeven after the first partial exit.

    • Adjust R-multiple to reflect partial closures.

  • Statistics

    • Compare trades with partial exits vs. full exits.

    • Analyze performance improvement or drawdown reduction.

  • Configuration

    • Toggle partial exits on/off.

    • Set the percentage to take off at each profit level.

3. Combined Strategy

The “ultimate” approach layers both trailing stops and partial exits:

  1. Enter a trade with an initial SL.

  2. Take partial profit at the first TP.

  3. Move stop to breakeven.

  4. Enable trailing stop for the remaining position.

  5. Target higher TPs on the remainder.

4. Implementation Timeline

  • Phase 1: Prepare codebase with placeholders (completed)

  • Phase 2: Implement trailing stops

  • Phase 3: Implement partial exits

  • Phase 4: Combine strategies and optimize

  • Phase 5: Add user configuration features

5. Performance Metrics

Planned new metrics to assess trailing stops and partial exits:

  • Average R-Multiple with/without trailing stops

  • Average R-Multiple with/without partial exits

  • % of Maximum Profit Captured via partial exits/trailing

  • Drawdown Reduction from partial exits

  • Win Rate Improvement attributed to trailing stops

Last updated