Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting are giving different number of trades compared live trading

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

    Backtesting are giving different number of trades compared live trading

    Hello, I am getting different number of trades on back-testing compared to live trading. Usually, some trades are not present in back testing. Actually my code is really heavy and works on multi instruments, It may have buffered due to running Calculate.OnBarClose and I think I have to apply TriggerCustomEvent() to solve the issue. But before that, I have few queries.
    1) Does this method solve the issues of missing trades on back-testing?
    2) How can we apply on back-testing on onbarupdate sections on calculations part of strategies, actually I'm doing excel extraction and also also getting some API responses.? Please provides examples.
    3) Any other approach so that we can get equal numbers of trade in live and backtest.


    Notes:- I am attaching 1 hours results, but I have verified very long periods .

    Thanks and regards,
    Mukesh

    Click image for larger version

Name:	image.png
Views:	214
Size:	11.2 KB
ID:	1225107
    Click image for larger version

Name:	image.png
Views:	177
Size:	9.9 KB
ID:	1225108​​

    #2
    Hello measmukesh,

    Thanks for your post.

    Please review the help guide document on the differences of real-time vs backtest (historical).
    http://ninjatrader.com/support/helpG...ime_vs_bac.htm

    A strategy running real-time (live brokerage account, live market simulation, Playback connection etc...) will produce different results than the performance results generated during a backtest.

    When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

    Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.

    Below is a link to the help guide on Calculate.
    https://ninjatrader.com/support/help.../calculate.htm

    To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar.
    Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

    High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

    Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

    SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm

    TickReplay — https://ninjatrader.com/support/help...ick_replay.htm

    Developing for Tick Replay -
    https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

    Additional information may be found in this NinjaTrader Forum post —
    https://ninjatrader.com/support/foru...mance?t=102504

    Please let us know if we may be of further assistance to you.​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello measmukesh,

      Thanks for your post.

      Please review the help guide document on the differences of real-time vs backtest (historical).
      http://ninjatrader.com/support/helpG...ime_vs_bac.htm

      A strategy running real-time (live brokerage account, live market simulation, Playback connection etc...) will produce different results than the performance results generated during a backtest.

      When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

      Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.

      Below is a link to the help guide on Calculate.
      https://ninjatrader.com/support/help.../calculate.htm

      To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar.
      Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

      High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

      Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

      SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm

      TickReplay — https://ninjatrader.com/support/help...ick_replay.htm

      Developing for Tick Replay -
      https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

      Additional information may be found in this NinjaTrader Forum post —
      https://ninjatrader.com/support/foru...mance?t=102504

      Please let us know if we may be of further assistance to you.​
      Thanks Brandon! My strategies always use to take trade on the open of next candle, I am trying to replicate things live as backtest, and I am getting exact same entry price and entry time compared to the live. My question is in this strategy why I am getting some missing trades in backtest compared to live. Does in this case intrabar granularity is also affecting?

      Comment


        #4
        Hello measmukesh,

        Thanks for your note.

        A strategy running real-time (live brokerage account, live market simulation, Playback connection etc...) WILL produce different results than the performance results generated during a backtest. You may not be able to get the backtest results to exactly match the results when the strategy is running live.

        This could possibly be caused by the script not having the intra-bar information to accurately fill an order at the exact price and time. In this case, intra-bar granularity should be added to the script and the script should submit orders to the added series as stated in my previous post.

        Ultimately, to determine exactly how your strategy is behaving, debugging prints should be added to the script to see how it is processing logic and placing trades. TraceOrders should also be enabled which will let you know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.

        https://ninjatrader.com/support/foru...121#post791121

        Let us know if we may assist further.​
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

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