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 vs Live

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

    Backtesting vs Live

    Hi,

    I'm new to ninjatrader and have a question. Why is that for example when i built on strategy builder, a simple strategy to buy/sell a contract when the price cross a certain MA on 5min chart, there's ALWAYS a delay of 1-2 bar after it crosses the MA before it execute (when backtesting)?

    When I run the strategy on Live simulation, the order get executed more or less exactly when the price cross the MA...

    Can anybody help me with this? Currently, there's a HUGE difference between the backtesting vs the live simulation.

    Thanks in advance.

    Tuan P.

    #2
    Welcome to the forums tphan!

    There some items to note about the CrossAbove()/CrossBelow() and how the Simulator works to fill orders with historical data and with realtime data.

    CrossAbove() and CrossBelow() look for the bar to be above or below a certain level, and then to cross over that level from a certain number of barsAgo. So for example, in the SampleMACrossover strategy, we see:

    CrossAbove(smaFast, smaSlow, 1)

    The method checks if smaFast was below smaSlow and has crossed above between the current bar and the last bar. I'll include the NinjaScript reference of this method for further reading.

    Backtesting with historical data, this would be our "trigger bar" and the order would then be filled by the OHLC values from the next bar which would be our "fill bar."

    To visualize this, I recommend testing with the SampleMACrossover strategy and use the mini data box with the middle mouse button to see what the SMA values are, when the cross occurs, and the bar where the fill occurred.

    It should also be noted that there will always be differences with backtesting historical data and performance with realtime data. I will provide publicly available documentation links in this post, and I will point out another thread that goes into these differences more in depth and how they can be reduced.


    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Ninjatrader_Jim,

      Thank you so much for your prompt reply. I sure did learn more about your program. In back-testing, is there a way to simulate a buy/sell the moment the price cross the MA (within the same bar)? Any tips or advice would be greatly appreciated.

      Thanks!

      Comment


        #4
        Originally posted by tphan View Post
        Hi Ninjatrader_Jim,

        Thank you so much for your prompt reply. I sure did learn more about your program. In back-testing, is there a way to simulate a buy/sell the moment the price cross the MA (within the same bar)? Any tips or advice would be greatly appreciated.

        Thanks!
        Use a secondary timeframe of 1sec, 1range or 1tick to process the orders. That would give you a close simulation of entering intrabar.

        ref: https://ninjatrader.com/support/help...nstruments.htm


        This gives you the most control over how entries are processed in backtest.

        However, NT8 can also do this under the covers for you, by using an order fill resolution of "High".

        ref: https://ninjatrader.com/support/help...ical_fill_.htm

        Comment


          #5
          Thanks for the links koganam!

          @tphan, koganam is pointing out some useful topics to understanding backtesting with Intrabar granularity. I would highly recommend reviewing those documents which will lead to a complete understanding of the Backtesting With Intrabar Granularity example. NinjaTrader_Chelseas's "Comparing real-time, historical, and replay performance" thread also goes further into detail on this.

          Backtesting with Intrabar Granularity sample can be referenced here - https://ninjatrader.com/support/help...ipt_strate.htm

          If there is anything else we can do to help, please let us know.
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rtwave, 04-12-2024, 09:30 AM
          2 responses
          20 views
          0 likes
          Last Post rtwave
          by rtwave
           
          Started by tsantospinto, 04-12-2024, 07:04 PM
          5 responses
          68 views
          0 likes
          Last Post tsantospinto  
          Started by cre8able, Today, 03:20 PM
          0 responses
          7 views
          0 likes
          Last Post cre8able  
          Started by Fran888, 02-16-2024, 10:48 AM
          3 responses
          49 views
          0 likes
          Last Post Sam2515
          by Sam2515
           
          Started by martin70, 03-24-2023, 04:58 AM
          15 responses
          115 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X