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

Running strategies on 1 tick charts

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

    Running strategies on 1 tick charts

    Does ninjatrader struggle with 1-tick charts. I've tried running strategies and the entries are very different and I experience slippage even when using limit orders. I am using the same data sets between live and backtest

    #2
    Hello samish18,

    Thanks for your post.

    Could you please clarify what exactly you are referring to?

    Did you add 1-Tick intrabar granularity to your strategy by adding a secondary 1-Tick series to the script, submitting orders to the added secondary 1-Tick series, and enabling Tick Replay?

    Or, are you backtesting a strategy on 1-Tick bars and running a strategy on a 1-Tick chart?

    See the NinjaTrader Support article below detailing adding intrabar granularity to a strategy to improve backtest order fill accuracy.

    Developer Guide: Improving Backtest Order Fill Accuracy with Intrabar Granularity - https://support.ninjatrader.com/s/ar...ar-granularity

    See this NinjaTrader Support article about comparing detailing comparing strategy results: https://support.ninjatrader.com/s/ar...rategy-Results
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      The latter, backtesting a strategy on 1-Tick bars and running a strategy on a 1-Tick chart.

      Comment


        #4
        Hello smaish18,

        Thanks for your notes.

        Is the strategy set to Calculate.OnBarClose, Calculate.OnPriceChange, or Calculate.OnEachTick?

        Do you have Tick Replay enabled when testing the strategy?

        If you look at the first bar on the Chart Display and the last bar on the Chart Display of the Strategy Analyzer, does it match the first/last bar on the Chart window you are comparing?

        Please test using the SampleMACrossOver strategy that comes with NinjaTrader. Are you able to reproduce the behavior when testing the SampleMACrossOver strategy?

        If so, please send us the exact steps and settings you are using to reproduce the behavior so we may try to reproduce it on our end.

        We look forward to assisting further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          In the State == State.SetDefaults it is set to calculate.OnEachTick (out of curiosity, because I am running on 1-Tick bars, would there be a difference if I used onBarClose?). I do not believe I have Tick Replay enabled, how do I enable it and what does it do?

          Comment


            #6
            Hello samish18,

            Thanks for your notes.

            If you are running the strategy on 1-Tick bars there likely will not be a difference between running the strategy with Calculate.OnEachTick and Calculate.OnBarClose.

            Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data. This is typically enabled when running a strategy on say 1-Minute bars or 150 Tick bars so logic can be processed intrabar with historical data.

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

            If you look at the first bar on the Chart Display and the last bar on the Chart Display of the Strategy Analyzer, does it match the first/last bar on the Chart window you are comparing?

            See this NinjaTrader Support article about comparing detailing comparing strategy results: https://support.ninjatrader.com/s/ar...rategy-Results

            Did you test running the SampleMACrossover strategy that comes with NinjaTrader as requested in my previous post?

            Please test using the SampleMACrossOver strategy that comes with NinjaTrader. Are you able to reproduce the behavior when testing the SampleMACrossOver strategy?

            If so, please send us the exact steps and settings you are using to reproduce the behavior so we may try to reproduce it on our end.​​
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              I set that start days to match when setting up. It takes a while to scroll back all the way on 1-tick bars, is there an easy way to verify the equivalent data. Additionally, if the conditions for taking a position only rely on the past 50 bars (say you are using a 50 SMA and a 10 SMA), on 1-Tick bars, wouldn't any differences between live and backtest even out after 50 bars?

              Comment


                #8
                Hello samish18,

                Thanks for your notes.

                There would not be an easier way to verify the data between tests. You would need to check the first bar and the last bar on the chart to ensure they are the exact same as the chart window you are comparing results to.

                See this forum thread about comparing realtime, replay, and historical (backtest) results: https://ninjatrader.com/support/forum/forum/ninjatrader-8/strategy-development/100192-comparing-real-time-historical-and-replay-performance?t=102504

                Is there a specific reason you are testing on 1-Tick bars?

                Are you planning on running the strategy on a 1-Tick bar real-time? Or, are you planning to run the strategy on a different bar, such as 1 Minute bar, 5 Minute bar, 1000 Tick bar, etc?

                Are you wanting to add intrabar granularity to a script to improve backtesting results?

                If there is any difference in data between tests then strategy results could be different. You would need to ensure that all the data being tested over is the same between tests. This is noted on the forum thread linked above.

                "For the tests to be even similar, it is necessary to test the exact same sets of data, without mixing and matching the data types."

                NinjaTrader_Jesse has replied to a very similar question posted by you on this forum thread: https://forum.ninjatrader.com/forum/...69#post1299469

                We look forward to assisting further.
                Last edited by NinjaTrader_BrandonH; 04-17-2024, 02:58 PM.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Verified that the two data sets are the same. I am running the strategy on 1-tick bars because that is my desired data set. I am not planning to run this strategy on a different time frame.

                  Comment


                    #10
                    Hello samish18,

                    Thanks for your notes.

                    Debugging steps would need to be taken to understand exactly what is behaving differently between the tests you are comparing.

                    Please see the forum thread below detailing comparing realtime, replay, and historical strategy results and the steps you should take for locating differences. This forum thread also contains a demonstration video and example script.

                    Comparing Realtime, Replay, and Historical Results: https://forum.ninjatrader.com/forum/...nce#post100192

                    And, see this NinjaTrader Support article which contains a developer's guide on comparing strategy results: https://support.ninjatrader.com/s/ar...rategy-Results
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Will do. Is this an issue you've encountered before with 1-tick charts, I do not have the same issue when operating on 1, 5, or 30 minutes charts.

                      Comment


                        #12
                        Hello samish18,

                        Thanks for your notes.

                        I have not seen any clients reporting this behavior recently or in the past.

                        Note that if there is a difference between any of the ticks you are testing over it could cause the results to differ.

                        You could follow the steps on the forum thread and NinjaTrader Support article linked in post # 10 to debug the logic of your script and locate differences that might be occurring between tests.
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #13
                          I ran both the live and backtest over the same period with traceOrders = true, but the files are too large to upload here.

                          Comment


                            #14
                            Hello samish18,

                            Thanks for your notes.

                            To clarify, did you follow the steps noted in the forum thread guide linked below to debug the script using Prints to identify where differences occur?

                            You would need to follow the steps on the forum thread below and use Prints to identify differences that may occur when comparing realtime results to backtest results. See the demonstration video in the link below for an in depth explanation on comparing realtime strategy performance to backtest strategy performance.

                            Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.


                            Brandon H.NinjaTrader Customer Service

                            Comment


                              #15
                              I added in my logic to the strategy listed in the link you sent and this was the output
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ETFVoyageur, Today, 02:15 AM
                              4 responses
                              28 views
                              0 likes
                              Last Post ETFVoyageur  
                              Started by drnoggin, Today, 12:19 PM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by synthhokie, Today, 12:00 PM
                              1 response
                              16 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by moneyexe, Today, 11:22 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by stevec1824, Today, 11:00 AM
                              2 responses
                              8 views
                              0 likes
                              Last Post stevec1824  
                              Working...
                              X