Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:	112
Size:	11.2 KB
ID:	1225107
    Click image for larger version

Name:	image.png
Views:	84
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.​
    Brandon H.NinjaTrader Customer Service

    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.​
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X