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

Getting Backtest to match Market Replay using Calculate.OnEachTick

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

    Getting Backtest to match Market Replay using Calculate.OnEachTick

    Hey guys -

    I've been reading up on the different fill options and I'm still having some problems getting my Backtest to match what I'm seeing in Market Replay. My strategy uses Calculate.OnEachtick and also IsFirstTickOfBar to set the triggers for entry. I believe I'm having issues with intrabar granularity fills as the backtest is often 1 bar off.
    If you look at my attached results, entries 1 and 3 are one bar off while entry 2 is correct.
    For the market replay, all 3 entries are correct.

    According to the help, if I set the Fill Resolution to High, 1 Tick, I would have intrabar fill logic but it looks like that's not working.
    What's my next step to get the backtest working properly?
    Attached Files

    #2
    Hello PN720,

    Thanks for your post.

    The High order fill resolution will only fill an order that has been placed. Your strategy may be set to run Calculate.OnEachTick, however, historical data does not contain all of the ticks that built the bar such as in Market replay data and will function only as Calculate.OnbarClose. If your strategy determines to place an order it would be at the end of the bar and an Order placed at the end of a bar would be filled on the subsequent bar, which is what you are observing.

    To have your indicators process on a tick basis in the strategy analyzer, you would need to use TickReplay in the strategy analyzer. Please note that using TickReplay will exclude you from then being able to select high order fill in the strategy analyzer so to obtain high order fill, you would need to also add a 1 tick data series to your strategy.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      Thanks for your prompt response. Just so I understand correctly, I only have 2 options to make the backtest match the Market Replay.

      1. Enable Tick Replay option in Strat Analyzer.

      OR

      2. Add a 1 Tick secondary data series in the code and add code to place orders against that secondary data series instead of the primary data series (i.e. 15 mins).

      Is this correct?

      If yes, I'm still not sure what High Order Fill (1 Tick) is used for?

      Comment


        #4
        Hello PN720,

        Thanks for your reply.

        You would need to use TickReplay to have your strategy calculate intrabar AND you would need a 1 tick series for the intrabar order fill. Please see: https://ninjatrader.com/support/foru...02&postcount=1 for further detail.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi again,

          The link in that info seems to contradict itself. This text says no code modifications are required.

          "In NinjaTrader 8, there have been two new enhancements so that programmers do not have to manually add this secondary series and code the script to for high accuracy fills (Order Fill Resolution) and for intra-bar actions (TickReplay)."

          But then, the intrabar sample adds the secondary 1 tick data series in code and places orders against that secondary data series.

          And then the TickReplay help says that

          "TickReplay does not provide fill prices for accurate order fills."

          Which is the problem I'm trying to solve.

          Sorry, I'm still confused on what needs to happen next.

          Comment


            #6
            Hello PN720,

            Thanks for your reply.

            In an effort to clarify, Historical data only consists of the OHLC data points and not of the ticks that made up the bar. This means that by default all historical data is processed Calculate.OnBarClose. This is true with historical bars on the chart as well as all bars in the strategy analyzer. All calculations are made end of bar. All orders are submitted end of bar and are filled on the next bar.

            For reference in the next section: Link to Tick Replay in the helpguide: https://ninjatrader.com/support/help...ick_replay.htm

            By using Calculate.OnEachTick (or OnPriceChange) in your strategy you are wanting the strategy to work based on intrabar movements but again with historical data there is no intrabar data. In NinjaTrader8 you do have an option to enable Tick Replay which will provide intrabar data so that your strategy will execute OnEachTick or OnPriceChange. From the helpguide section, "Tick Replay is used to playback 1 tick historical data to build the bars as if they had been build live, this means that tick data will be thrown as Market Data events in historical and subsequently OnMarketData and OnBarUpdate events will be called as if it was live. This provides more granular tick related information and can be helpful if you need to know the most recent last price, last volume, best ask price, or best bid price that occurred on historical data during the bar." This means that your historical indicator calculations will be made relatively the same as if live and and using OnEachTick (Or OnPriceChange)

            Also with reference to the tickReplay section of the helpguide, please observe Note 1, " Tick Replay was NOT designed to provide accuracy in backtesting concerning order fills and execution and should NOT be used to expect the exact sequence of executions as running a strategy on live data. For greater order-fill resolution and accuracy in strategy backtesting, you can use the High Fill Resolution in the Strategy Analyzer. Furthermore, you cannot combine both Tick Replay and High Order Fill resolution."

            So the above is advising the adding tick replay alone will not improve the order filling process, only the intrabar ordering (not filling) process. When tick replay is used, you cannot now select High order fill to provide the intrabar fills of orders, so to work around this, you can add a 1 tick series to your strategy to help with the intrabar order filling process.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hey Paul,

              I'm interested in this topic as well. So if one's strategy is on a 1min chart, one simply just have to add a secondary data series in State.State.Configure then proceed to use high resolution fill at 1 tick in strategy analyzer and enable tick replay to resolve this issue? Is there any other direction?

              so I added the following line in State.Configure
              AddDataSeries(BarsPeriodType.Tick, 1);

              and if the strategy uses Calculate.OnEachTick and in the strategy analyzer, one selects TickReplay, it will automatically fill orders and calculate every tick instead of OHLC? Because fill resolution is not available so one cannot choose high resolution or 1 tick.
              Last edited by Boonfly8; 09-11-2018, 04:23 PM.

              Comment


                #8
                Hello Boonfly8,

                Thanks for your post.

                "Because fill resolution is not available so one cannot choose high resolution or 1 tick.", Correct, when choosing Tick Replay for the Calculate mode you cannot then use the High order fill and this is why you add the 1 tick series to your strategy, to basically replace the High order fill option.
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by frslvr, 04-11-2024, 07:26 AM
                8 responses
                111 views
                1 like
                Last Post NinjaTrader_BrandonH  
                Started by stafe, 04-15-2024, 08:34 PM
                10 responses
                44 views
                0 likes
                Last Post stafe
                by stafe
                 
                Started by rocketman7, Today, 09:41 AM
                3 responses
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by traderqz, Today, 09:44 AM
                2 responses
                5 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by rocketman7, Today, 02:12 AM
                7 responses
                31 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X