Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calendar Spread Strategy

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

    Calendar Spread Strategy

    I am working on some code to backtest/trade calendar spreads. The code seems to be working properly when I use expiration dates from 06-16 through 06-17. However, If I add in the 03-16 contract the code automatically disables itself and shows no errors. See the link below for a video showing the problem. I have also attached the code I am using.

    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


    Also, the Instrument Manager will not allow me to add instruments with expiration prior to 2016 to a list. How can I load the prior contracts? The code is not allowing me to use instruments that haven't been added to a list, so even if I get a resolution to the issue above, I am still unable to test this strategy back further than 2016.
    Attached Files

    #2
    Hello toptrader,

    Thank you for your note.

    It is not a good idea to pass Ticker/Symbol variables into the strategy via Add(), as you are doing. Because if you disable strategy then change parameter, the strategy won't reflect that change because the strategy has already been initialized.

    It is suggested you hard code the contract months/symbol names into the strategy.

    So on Line 74, rather than your for loop, you should use,
    Code:
    Add(“ES 03-17”, PeriodType.Day, 1);
    Add(“ES 06-17”, PeriodType.Day, 1);
    Or if you would like to keep things as they are, you will have to remove the strategy and re add it to the chart each time you make a change.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      I tried hard coding the contract months as suggested, but the same issue is still occurring.

      Also, the Instrument Manager will not allow me to add instruments with expiration prior to 2016 to a list. How can I load the prior contracts? The code is not allowing me to use instruments that haven't been added to a list, so even if I get a resolution to the issue above, I am still unable to test this strategy back further than 2016.

      Comment


        #4
        Hello TopTrader,

        To add contracts pre 2016, shut down NinjaTrader, go to your PC clock on the taskbar, right click, adjust data and time, then change the year to 2015. Start NT.

        Regarding the issue still occurring when you hard code the contracts in, could you please share the revised code so I may have a look?

        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Attached is the updated version of the code. Thank you for your assistance!
          Attached Files

          Comment


            #6
            Hello Toptrader,

            I was able to apply the strategy and see its lines/text on the chart when I went to Control Center>Tools>Options>Data Tab and set the Merge Policy to MergeBackAdjusted.

            I then applied the strategy to an ES ##-## chart, with a daily time frame and bars to load set to 3650.

            Are you able to reproduce?

            I look forward to your reply.
            Attached Files
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              I do get the same plot when I follow your instructions, but the plot is not correct. The current spread between ES 03-17 and ES 06-17 is about 6 points. Your image is showing it is at 0 points, and it is also showing a large increase in the spread on each rollover.

              When I set the merge policy to DoNotMerge, it looks like the spread is being calculated properly. However, this only works if I do not include the 09-15, 12-15, and 03-16 contracts (see the image below). If I include even the 03-16 contract, the strategy automatically disables itself and gives no indication of why.

              Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.

              Comment


                #8
                Hello Toptrader,

                Upon testing I think the issue is that your strategy is requesting data for which is not being returned. If you type into a chart, ES 09-15 or ES 12-15, does the chart come up blank?

                Regarding adding just the ES 06-17 contract, since this is not the front month, there is an issue with using the ES ##-## symbol. Even if I change the roll date for the ES 06-17 to last week in the instrument manager, ES ##-## does not print the June contracts price. This is because the continuous data comes from the data provider.

                I was able to get your strategy to work with the 2015 contracts commented out and the strategy applied to a ES 06-17 chart, after I added the following under your BarsInProgress!=0 return comment.

                if(CurrentBars[0]<10)return;

                I look forward to your reply.

                I have attached the modified indicator.
                Attached Files
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  I do have data for all the contracts I am referencing:

                  Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


                  I tried your code, but it still does not resolve the issue. I have simplified the code significantly in the attachment. This is 6 lines of code in the Initialize method, and no code anywhere else. When I try to enable this strategy, it automatically disables itself with no error messages. As stated above, I do have data for all of the contracts I am trying to access, and I also have all of them in an instrument list. Would you be able to elaborate on why this code will not enable?
                  Attached Files

                  Comment


                    #10
                    Hello toptrader,

                    In the script your provided, if you comment out the 03-16 ES contract you can run the strategy without it disabling itself. The reason for this is that the data range of each contract must overlap each other, and given the ES 06-17 first trade was after the March 03-16 contract expired, your calls to Add contract data are failing.

                    I would suggest reducing the amount of contract months in your indicator or ensuring the contract months overlap.

                    Please let us know if you need further assistance.
                    Alan P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by DJ888, 04-16-2024, 06:09 PM
                    4 responses
                    12 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by terofs, Today, 04:18 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post terofs
                    by terofs
                     
                    Started by nandhumca, Today, 03:41 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post nandhumca  
                    Started by The_Sec, Today, 03:37 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post The_Sec
                    by The_Sec
                     
                    Started by GwFutures1988, Today, 02:48 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Working...
                    X