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.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Calendar Spread Strategy
Collapse
X
-
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.
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.Tags: None
-
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);
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
-
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
-
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
-
Attached is the updated version of the code. Thank you for your assistance!Attached Files
Comment
-
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.Alan P.NinjaTrader Customer Service
Comment
-
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.
Comment
-
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 FilesAlan P.NinjaTrader Customer Service
Comment
-
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
-
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 Mestor, Today, 03:15 AM
|
0 responses
1 view
0 likes
|
Last Post
by Mestor
Today, 03:15 AM
|
||
Started by Mestor, 03-10-2023, 01:50 AM
|
11 responses
305 views
0 likes
|
Last Post
by z.franck
Today, 02:29 AM
|
||
Started by Padan, Today, 02:02 AM
|
0 responses
6 views
0 likes
|
Last Post
by Padan
Today, 02:02 AM
|
||
Started by bukowa, 11-09-2023, 06:07 PM
|
20 responses
407 views
0 likes
|
Last Post
by Adfra
Today, 01:36 AM
|
||
Started by yertle, Yesterday, 05:49 PM
|
2 responses
11 views
0 likes
|
Last Post
by yertle
Today, 12:12 AM
|
Comment