Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to modify the execution price and date in a backtesting-only strategy?

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

    How to modify the execution price and date in a backtesting-only strategy?

    I am working with a team to build a strategy for backtesting only. This strategy is based on daily and weekly stochastics, not anything intraday. The strategy calls for buying or selling the security at EOD on the same bar that the signal is given. (In real life, we can see when the signal will happen in the last few minutes of the day, and buy just before the close.) For the backtesting we simplify by using the close price of the day. In Ninjatrader by default it is buying the next day at the open price. What is the best way to change that to the closing price of the signal day?

    I am brand-new to the forum. This is my first post! Please forgive me and tell me if have any forum protocol mistakes.

    Thanks!

    #2
    Typically, this would be done by using intraday data to place the orders (even if your analysis is all on daily bars) and just placing the order a few minutes before the close just like you do in real life.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Being new to NinjaTrader, I am only using the Kinetick EOD free data so far. I am a bit confused by the different NT options to get intraday data. I am only using NT for backtesting, not my trading account, so can someone tell me the best option for intraday backtesting data? I need to backtest 15 years at the minimum.

      BTW, I use TD Ameritrade as my trading account, and I hear that I can hook that in to NijaTrader, but I havent seen how to do that yet, and I read that only 50 days of intraday data is available if I use TD Amer as my data feed.

      Thanks!
      Last edited by rikelleher; 04-23-2023, 02:52 PM.

      Comment


        #4
        Is there a way to do this with EOD prices? My team is doing this with EOD prices in 2 other backtesting systems and we want to be able to compare "apples to apples" results.

        Is it recommended to make changes to the dates and prices in the OnExecutionUpdate() method, or to edit the Execution objects directly, or something similar?

        BTW, we are only targeting this backtesting for equities and ETFs.

        Thanks
        Last edited by rikelleher; 04-23-2023, 03:22 PM.

        Comment


          #5
          I do not believe, until NinjaTrader corrects me about this, that they would permit you to manually inject a fill price and force it to get a fill at the close of the day or the like. That would be a violation of the "no future peeking" philosophy.

          You might want to read this post and the thread that leads up to it for a similar discussion. https://forum.ninjatrader.com/forum/...38#post1222938
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment


            #6
            Hello rikelleher,

            Thank you for your inquiry.

            When backtesting in the Strategy Analyzer, order fills are based on OHLC data and that is why you are seeing orders fill on the open of the next day's bar rather than a few minutes before a daily bar closes. With only EOD data, there is no way to get intraday order fills from the Strategy Analyzer. One of the options to get intrabar fills is to use the "High Order Fill Resolution" in your backtest settings. This allows you to add a second, more granular data series to base the fills on. The most granular option is 1-tick, though this is also more resource-intensive and could result in longer loading times. The following link covers more details about the historical fill algorithm and the different order fill resolution options:


            Another option for intrabar granularity is to develop your strategy so that a smaller data series is added programmatically and orders are placed on that added series. Again, the most granular option would be a 1-tick data series. We have a reference sample demonstrating this concept here:


            We have a page about the discrepancies between real-time results and backtest results in NinjaTrader here:


            You have mentioned that you need to backtest at least 15 years for equities and ETFs. Since you would not have that full scope of data available from TD Ameritrade, if you are able to find the data files for more granular data for your desired instruments and time periods, you could potentially import that historical data into NinjaTrader for use in your backtests. Some third-party services offer historical data files for download. As long as the data is in the proper file type and format, NinjaTrader can read that data. More information on importing historical data may be found here:


            If you are interested in connecting to TD Ameritrade in NinjaTrader, please see the connection guide here:


            Please let us know if we may be of further assistance.

            Comment


              #7
              Thank you Emily. I will explore the intraday options and also importing the minute-by-minute data I need.

              I followed the instructions for connecting to TD Ameritrade. I get the same failure that I had in the past. I complete steps 6a and 6b (authorizing NinjaTrader to access my TD Ameritrade account). but it never goes to step 7 and gives no error message.
              Click image for larger version

Name:	image.png
Views:	177
Size:	26.4 KB
ID:	1248232
              It says I must use IE11 for this, but MSFT wont let me download IE11. It says I can use IE compatible mode in MS Edge, which is what I did.
              How do I complete this?

              Thanks

              Comment


                #8
                Hello rikelleher,

                Thank you for your reply.

                Were you able to complete step 6 successfully where you log in and click Allow for the TD Ameritrade Authorization? In the connections window of NinjaTrader, does it still say 'Authorize' or does it now show 'Authorized' on the TD Ameritrade connection?
                Based on your description, I suspect you may be using an older version of NinjaTrader. What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?) The latest versions are 8.1.1.3 and 8.0.27.1. If you are on an older version, please update to the latest version of NinjaTrader Desktop with the steps below.
                • Login into the NinjaTrader Account Dashboard
                • Click "Download" in the bottom left-hand corner of the sidebar
                • Next select "Download" in the "Most Recent Release" Window in the main screen
                • Once the installation had downloaded, ensure any previous version of NinjaTrader is closed before running the installation package.
                  • Note: You may need to locate this in your "Downloads" folder in a Windows File Explorer
                ​Please let me know if I may be of further assistance.

                Comment


                  #9
                  Thank you.

                  Yes, I completed step 6 successfully where I logged in and clicked Allow for the TD Ameritrade Authorization, and in the connections window of NinjaTrader, it still says 'Authorize'. No change to "Authorized."

                  I am using version "8.0.25.0 64-bit"

                  You said​I am getting incorrect username or password. I dont know which is incorrect. Is this a different login than I used to register for this forum?

                  Comment


                    #10
                    Hello rikelleher,

                    Thank you for your reply.

                    Since version 8.0.26.1, an update was implemented to how TD Ameritrade connections are authorized and this should allow you to connect properly once updated. For more info, please see the release notes here:


                    As for the NinjaTrader Account Dashboard login, it is different than your forum credentials. Since you are using version 8.0.25.0, I suspect you have not yet created an account on the dashboard. You will need to click "Get Started" on the right-hand side of the login screen to create an account, and then you should be able to log in and access the download links.

                    Please let me know if I may be of further assistance.

                    Comment


                      #11
                      I
                      • created my account,
                      • upgraded my desktop app to 8.1.1.3 64-bit
                      • and connected to TD Ameritrade.
                      Thanks!

                      Comment


                        #12
                        Does any historical intraday market data (equities for me) come with an account? Or is it only the completely simulated market data for 14 days?

                        Is the only way to get historical intraday equity data the $75 subscription? Again, I am only planning to use NinjaTrader for backtesting, not trading an account, at this time.

                        Thanks

                        Comment


                          #13
                          Hello rikelleher,

                          Thank you for your reply.

                          Glad to hear you got connected to TD Ameritrade. The only free equities data offered in NinjaTrader is from the Kinetick - End Of Day (Free) connection. A subscription to a data provider would be required to get historical intraday equities data in the platform. We have the different data types, including which instruments are supported, listed in the data by provider grid here:


                          Otherwise, as I previously mentioned, you may be able to find a third party that offers historical data files that you may import into NinjaTrader:


                          Please let us know if we may be of further assistance.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by NullPointStrategies, Today, 05:17 AM
                          0 responses
                          20 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          119 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          63 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          41 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          45 views
                          0 likes
                          Last Post TheRealMorford  
                          Working...
                          X