Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Back testing and optimizing a strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Back testing and optimizing a strategy

    Hi all,




    I’m currently running into an issue with my strategy that works well in real-time but causes problems during backtesting in the Strategy Analyzer. Here’s the situation:

    Problem Overview:
    • My strategy involves placing trades with two profit targets, stop-loss adjustments, and breakeven logic. In live trading, I manage these using OnExecutionUpdate to dynamically handle stop-loss adjustments, partial exits, and moving stops to breakeven + pips.
    • I’ve used the State.Realtime condition in parts of my code to handle execution and position management for live trades.
    Issue During Backtesting:


    When I remove the State.Realtime condition to enable backtesting, the Strategy Analyzer runs into issues where:
    1. Partial trades or incorrect position sizes appear in historical data.
    2. Breakeven adjustments, stop-loss movements, and profit target hits are not simulated properly since these are handled in real-time with dynamic logic.
    What I Want to Achieve:
    1. Accurate Backtesting: I need my backtests to simulate the behavior of live trading as closely as possible, including proper handling of stop-loss, profit targets, and breakeven logic without relying on real-time execution conditions.
    2. Keep Real-Time Logic: I want to retain the real-time execution logic for live trading, but I’m not sure how to properly isolate it without affecting backtesting results.
    Key Questions:
    • How can I simulate my real-time order management logic (breakeven, stop-loss adjustments, etc.) accurately during backtesting, given that I rely on OnExecutionUpdate and dynamic position management in live trading?

    Any advice on structuring the strategy to accommodate both backtesting and live trading modes without losing accuracy would be greatly appreciated!​

    #2
    Hello Joseph Davidow,

    That may be one of the expected differences in backtesting depending on how you coded the strategy, you can see the following link for some ideas of differences. You would otherwise have to use prints in the script to know what specific part of the logic is working differently to know what needs to be changed to have backtesting perform more similar to realtime.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    110 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    59 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    37 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    41 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    78 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X