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

Changing Contracts

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

    Changing Contracts

    The way I have been backtesting is using market replay. I open a chart for a CL contract, set the start and end dates, load my strategy and playback.
    So I test a month at a time since CL is 1 contract per month.
    How would I handle the case where, say, I'd like to playback 2 months for testing? But then how would I get the chart contract to change?

    #2
    Hello reynoldsn,

    Thank you for your post.

    If your merge policy is set to MergeBackAdjusted (the default setting), it will include an offset to seamlessly merge between contract months.

    https://ninjatrader.com/support/helpGuides/nt8/merge_policy.htm

    MergeNonBackAdjusted provides a continuous contract, though there may be gaps between contract months because there is no offset applied.

    DoNotMerge will not merge with any other contract months, so the test would only be run for any data available for the selected contract month.

    Please let us know if you have any further questions.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply.
      (and to be clear, I'm not using Strategy Analyzer)

      Let me add some specifics so I can understand your response.

      Say I am backtesting (with market replay) 2 CL contracts, CL 03-24 and CL 04-24
      They way I test is to start with CL 03-24. I load that chart and then set the market replay control from 1/18/2024 through 2/17/2024.
      I load my strategy and then play back and gather the results.

      Then for the next contract, I set the chart to CL 04-24, I set the dates on the market replay timer from 2/18/2024 through 3/17/2024
      Then I load same strategy and playback.

      The important point being I am running certain dates for certain contracts.

      In this scenario what do I set the merge policy to?
      Do I start the chart with the CL 03-24 contract?

      Then say I run 2 continuous months, CL 03-24 and CL 04-24. After replay finishes and I scroll back through the chart, will I see the contract change between 2/17/2024 and 2/18/2024 as described above?

      Comment


        #4
        Hello,

        This applies to all charts, including those in Playback.

        To clarify the way contract front-months work with MergeBackAdjusted, if you select for instance 06-24 as your front month expiry, and you iterate over 3 years, you will have data available for the entire 3 year range automatically. The historical data server you are pulling from has organized data in such a way that you can pull a continuous feed from a single front month going back as far as there is historical data for that instrument.

        If you only want to test data for the selected contract, use DoNotMerge.

        If you want to pull continuous data from a single contract month, going as far back as there is available historical data, use MergeBackAdjusted or MergeBackNonAdjusted.

        " After replay finishes and I scroll back through the chart, will I see the contract change between 2/17/2024 and 2/18/2024 as described above?"

        It depends on what you have your merge policy set to and what contract month you have selected.

        So if you select CL 04-24 with MergeBackAdjusted, you will see historical data going as far back as there is available / loaded on your chart. So you would be able to go back and test over CL 03-24 without explicitly selecting this as the front month.

        If you select DoNotMerge, you will only see data available for the selected contract month.
        Last edited by NinjaTrader_Gaby; 05-09-2024, 08:37 AM.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          ok, so I am using the default of MergeBackAdjusted

          continuing with my example, I set the front month (contract on the chart) to CL 04-24

          I connected to playback and set my dates to start with the CL 03-24 contract, that is, 1/18/2024 through 3/17/2024

          and yes, trades were taken in both months, so that might be a good sign.

          However, when I run Strategy Performance, all of the contracts show CL APR24 - the ones in Jan should at least show CL MAR24
          I actually wouldn't mind but when I ran the months individually, the trading results are significantly different so I need to see what contract is being used and on what date.
          again, I need CL MAR24 to be used from 1/18/2024 through 2/17/2024 and CL APR24 to be used 2/18/2024 through 3/17/2024

          if Strategy Performance showed the right contracts, then I could also examine when it switches contracts.

          My screen shot shows the first row of Strategy Performance - you see a contract of CL APR24 and a trade on 1/22/2024 but that trade is supposed to be taken on the CL MAR24 contract.

          Please let me know if you need clarification.
          Thank you
          Attached Files

          Comment


            #6
            Hello reynolds,

            The Strategy Performance will show the month you are testing over. Since you set the front month to CL 04-24, all trades will show on the CL 04-24.

            It is not possible to determine what contract is being used for a particular trade when using MergBackAdjusted.

            What you can do is to export the "Trades" display of the to a spreadsheet and then filter it (though the spreadsheet functions) by dates related to the rollovers yourself.

            On a chart, you could manually add vertical lines to visually define the contract dates.
            Gaby V.NinjaTrader Customer Service

            Comment


              #7
              Ok, I think a lot of it may have to do with following NT's rollover schedule.
              While I was using the 18th as rollover, NT tends to use the 15th.
              Having said that I have a new chart problem - I just posted the issue about 5 minutes ago.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by sdauteuil, 09-23-2021, 10:16 AM
              7 responses
              1,247 views
              0 likes
              Last Post marcus2300  
              Started by sofortune, 05-18-2024, 11:48 AM
              2 responses
              32 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by Zach55, 02-19-2024, 07:22 PM
              2 responses
              65 views
              0 likes
              Last Post lbadisa1  
              Started by JGriff5646, Yesterday, 05:47 PM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by AlphaOptions, 06-18-2013, 08:24 AM
              9 responses
              2,203 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X