Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting breakeven fails in strategy snalyzer

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

    Setting breakeven fails in strategy snalyzer

    I have a strategy that modifies a stoploss after a certain offset. This works great in real time and playback but the strategy analyzer fails.
    It seems the position is already closed by the time the modification order is processed:

    "Cancelled pending exit order, since associated position is closed,"​

    Strategy analyzer:
    Click image for larger version

Name:	image.png
Views:	155
Size:	3.1 KB
ID:	1342103

    Playback:
    Click image for larger version

Name:	image.png
Views:	98
Size:	139.3 KB
ID:	1342104
    Click image for larger version

Name:	image.png
Views:	98
Size:	161.9 KB
ID:	1342105

    Is there a recommended way to handle intrabar order modification so that strategy analyzer is able to process it accurately?

    Additional info, i have added a tick data series and am using tick replay in the strategy analyzer.

    HTML Code:
    if (BarsInProgress == 0)
    {
        if (Position.MarketPosition != MarketPosition.Flat && EnableBreakEven)
        {   
            CheckBreakEven();​
        }
    }

    #2
    Hello spencerduran

    Thanks for your message.



    This behavior is expected in NinjaTrader 8 due to differences between real-time behavior and Strategy Analyzer historical backtesting, especially with intrabar order modifications.

    In your case, since you already have tick replay enabled, and you have added a 1 tick data series, you need to ensure that the order is sent and filled on the secondary bar series. While the entry condition is triggered on the primary bar series, the order needs to be sent on your added 1 tick data series, or BarsInProgress = 1.

    For example, the way the bar series is determined is by the first parameter: 0 = primary bars,1 = secondary bars, etc.

    EnterLong(1, 1, "Long: 1min");

    EnterLong()

    BarsInProgress

    Also, ensure to have Calculate set to OnPriceChange or OnEachTick.

    The link below contains a sample code demonstrating how to improve backtesting NinjaScript Strategies with an intrabar granularity

    SampleIntraBarBackTest

    We also have a more in-depth developer guide with more information on how to improve backtest order fill accuracy with intrabar granularity.

    NinjaScript Developer Guide


    Feel free to reach out with any other questions or concerns.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    49 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    67 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X