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

How to test futures data for a year

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

    How to test futures data for a year

    Hello,

    I'm wondering how to backtest futures (MNQ, NQ, ES) data continuously for a year using a strategy analyzer or optimization.

    Thanks in advanced

    #2
    Hello ftraderXX,

    Thanks for your post.

    You may backtest futures in the Strategy Analyzer by using the front month (I.E. ES 03-22 as of today,) and using the default Merge Policy of Merge Back Adjusted. Merge Back Adjusted will merge previous contract months to the next, which recreates a continuous contract with historical data.

    Merge Policy is set in the Control Center's Tools > Options > Market Data menu.

    Also to note, a NinjaScript strategy must first be created or installed in order to run a backtest.

    MergePolicy - https://ninjatrader.com/support/help...rge_policy.htm

    More information on running backtests and optimizations can be found below.

    Backtest a strategy - https://ninjatrader.com/support/help...a_strategy.htm

    Optimizations - https://ninjatrader.com/support/help...a_strategy.htm

    Developing NinjaScript strategies - https://ninjatrader.com/support/help...strategies.htm

    Let us know if you have any questions.
    Last edited by NinjaTrader_Jim; 02-03-2022, 09:31 AM.
    JimNinjaTrader Customer Service

    Comment


      #3
      My merge policy is set as "Merge Back Adjusted" and as an instrument, I have chosen MNQ 03-22 and as a time period 1.Jan.2021 - 02.Feb.2022. Why the strategy only takes trades from the middle of November 2021 till today.

      Added a few illustrative pictures as well

      Comment


        #4
        Hello ftraderXX,

        There may be an issue getting the data where the Strategy Analyzer won't have that data to backtest or the strategy trades are not being triggered by the logic, or the orders are triggered but are being ignored.

        You can switch the Display Selector in the Strategy Analyzer to a view a chart to make sure you have a complete set of data for that time.

        You can also test the SampleMACrossover strategy to confirm if there is an issue specific with to your strategy.

        If you can confirm the data is there, orders submissions are either not being reached, or would be ignored.

        Confirming that the logic is reaching the order submission methods is the next troubleshooting step.

        Debugging your NinjaScript strategy to see why actions are not being taken

        The first step will be to reproduce the symptoms so you can add debugging prints for testing.

        After the issue is reproduced, you will want to add debugging prints to confirm that the logic in question is being reached and allowing the actions to be taken.

        I.E.

        Code:
        if (Close[0] > Open[0])
        {
            Print("Condition became true. Order submission method is reached");
            EnterLong();
        }
        If the logic is not allowing the actions to be taken, the conditions controlling those actions will need to be debugged so you can observe how they evaluate and see why they are not allowing the actions to be taken.

        I.E.

        Code:
        Print("Close: " + Close[0] + " Open: " + Open[0]);
        if (Close[0] > Open[0])
        {
            Print("Condition became true. Order submission method is reached");
            EnterLong();
        }
        The above print will tell you what the Close and Open values are and can tell you why the condition below has/has not become true.

        If you are seeing your order submission logic being reached, but it is not executing, there may be an issue where the strategy is hitting an internal rule that is not allowing you to re-enter. TraceOrders can be enabled in the strategy (set in State.SetDefaults or in the Strategy Builder under Default Properties) so it prints its order feedback, and you may also observe the log tab of the Control Center for additional hints.

        Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm
        TraceOrders - https://ninjatrader.com/support/help...aceorders2.htm
        Debugging in the Strategy Builder - https://drive.google.com/file/d/1mTq...w?usp=drivesdk
        Debugging Demo - https://drive.google.com/file/d/1rOz...w?usp=drivesdk
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello Jim,

          Followed your advice and tried to run a backtest with the SampleMACrossover from 01/01/2021 to 03/02/2022. I'm having the same issue, where the strategy is only taking trades from 01/11/2021 - 03/02/2022, and not from an earlier period. Therefore I'm pretty positive that there are some problems with the data not with the strategy. Added few illustrations as well.

          Comment


            #6
            Hello ftraderXX,

            Please use the Chart Display, or open a new chart with those dates set to make sure you have data on for that time frame (you will need to be connected to your data provider to request historical data)

            The Chart Display can also help you visualize where crossovers occur and where trades would be triggered with the SampleMACrossover strategy. We can also confirm the chart starts at the expected date. (This would match opening a regular chart with the same settings.)

            Please also note that you also have Bars Required to trade set to 20. So we would need 20 500 Tick bars and a crossover to be seen for the first trade to be triggered and allowed.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hello Jim,

              I'm connected to Interactive Brokers Gatewat through Ninjatrader and managed to download full-year(2021 Jan till today) historical data. If I run my strategy in a strategy analyzer and used 5/10/15 minutes timeframe charts then everything works. The chart displays a full-year data and strategy works as it should be, even the SampleMACrossover strategy. However, if I change to tick chart (e.g 1000t chat) on MNQ 03-22 then data goes back to November 2021 only. Is this IB related problem that they don't provide expired futures contracts tick data anymore or what's going on?

              In the pictures, you can see that on the minutes' chart everything works as it should be.
              Attached Files

              Comment


                #8
                Hello ftraderXX,

                Interactive Brokers does not provide historical tick data to NinjaTrader. It is a limitation of the Connection Adapter in NinjaTrader and how it is able to request historical tick data from IB's API.

                Many users consider using a dedicated Market Data Provider service to get historical tick data with Interactive Brokers.

                A breakdown of our supported data providers and the data they offer can be found below.

                Data By Provider - https://ninjatrader.com/support/help...y_provider.htm
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
                27 responses
                88 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by naanku, Yesterday, 07:25 PM
                2 responses
                12 views
                0 likes
                Last Post bltdavid  
                Started by dcriador, Yesterday, 10:45 AM
                3 responses
                27 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by SnailHorn, Yesterday, 10:49 PM
                2 responses
                14 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by PaulMohn, Yesterday, 06:59 PM
                1 response
                25 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X