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

Expire Dates

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

    Expire Dates

    Hello,

    How can I find out when (which way) each contract expire?
    I mean if for one future expire each month and for another future each quartal?


    Of course in code.

    Thanks,

    Martin

    #2
    Hi Luigio.

    Thank you for posting.

    Yes, you can see the expiry for a contract by using -
    Code:
    Instrument.Expiry
    This will return a DateTime structure for you that you can have printed to the output window or use as a check in the code for when to rollover.

    Here is a link from the online help guide on the code
    http://www.ninjatrader.com/support/h...tml?expiry.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks, but if I open for example daily chart for CL 10-13 two years back it still will write CL 10-13 even for date e.g. 1.1.2012, and I would like to know the expire date for each date separately.

      Comment


        #4
        Luigio,

        You would then want to use this code to get the rollover dates.
        Code:
        Instrument.MasterInstrument.RollOverCollection[index].Date
        Note that the RollOverCollection is an indexed system just like the bars ago.

        You can run this through a For loop to print out the different rollover dates that in the collection.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Thanks a lot Cal.

          That is exactly what I am looking for.
          I have one more question:
          When I put it to a loop this is result of this script:
          Code:
          Print(Instrument.MasterInstrument.RollOverCollection[i].Date);
          Print(Instrument.MasterInstrument.RollOverCollection[i].ContractMonth);
          Does follows mean that I should switch to the 9th of 2012 ContractMonth at 19.7?? etc..
          19.7.2012 0:00:00
          1.9.2012 0:00:00

          20.8.2012 0:00:00
          1.10.2012 0:00:00

          19.9.2012 0:00:00
          1.11.2012 0:00:00

          18.10.2012 0:00:00
          1.12.2012 0:00:00

          15.11.2012 0:00:00
          1.1.2013 0:00:00

          17.12.2012 0:00:00
          1.2.2013 0:00:00

          18.1.2013 0:00:00
          1.3.2013 0:00:00

          Comment


            #6
            Luigio,

            The date settings are per your PC clock settings.

            In this case -
            DD-MM-YYYY

            18.1.2013 0:00:00
            is equal to January 18th, 2013 at midnight or 12:00 AM
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Oh, I see, Thanks a lot for you support.

              Comment


                #8
                Hello,
                I have another problem, it worked for one instrument, I have this function
                Code:
                for(int i = idxCurrContract + 1; i != Instrument.MasterInstrument.RollOverCollection.Count; i++)
                			{
                				string name = Instrument.MasterInstrument.Name;
                				string month = Instrument.MasterInstrument.RollOverCollection[i].ContractMonth.Month.ToString();
                				string year = Instrument.MasterInstrument.RollOverCollection[i].ContractMonth.Year.ToString().Substring(2, 2);
                				
                				if(month.Length == 1)
                					month = "0" + month;
                				if(year.Length == 1)
                					year = "0" + year;
                				string instName = name + " " + month + "-" + year;
                				//myInstruments.Add(instName);
                				Add(instName, PeriodType.Day, 1);
                			}
                to add All expiration since current up to the last traded expiration.
                But it works only for Instrument for which I have opened the chart. I would like to do it somehow like this:

                Code:
                //Define Instrument list
                			alInstruments.Add("CL");
                			alInstruments.Add("ZS");
                			alInstruments.Add("xx");
                			
                			idxCurrContract = RollOver(DateTime.Now);
                			
                			for(int i2 = 0; i2 != alInstruments.Count; i2++)
                			{
                				[B][U]//Here I need to define different instrument[/U][/B]
                				for(int i = idxCurrContract + 1; i != Instrument.MasterInstrument.RollOverCollection.Count; i++)
                				{
                					string name = Instrument.MasterInstrument.Name;
                					string month = Instrument.MasterInstrument.RollOverCollection[i].ContractMonth.Month.ToString();
                					string year = Instrument.MasterInstrument.RollOverCollection[i].ContractMonth.Year.ToString().Substring(2, 2);
                					
                					if(month.Length == 1)
                						month = "0" + month;
                					if(year.Length == 1)
                						year = "0" + year;
                					string instName = name + " " + month + "-" + year;
                					//myInstruments.Add(instName);
                					Add(instName, PeriodType.Day, 1);
                				}
                			}

                Comment


                  #9
                  Luigio,

                  You should be able to use BarsArray[].Instrument to pick which instrument you would like to print out the rollover dates.

                  Example -
                  Code:
                  BarsArray[1].Instrument.MasterInstrument.RollOverCollection[1].Date
                  This will use the secondary data series you define and grab the rollover data.
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    But I have not added the Instruments, I use the loop to add them.
                    So I think I can use that.

                    Comment


                      #11
                      What I actually need to do is:
                      I have opened Chart e.g. for
                      CL 11-13
                      then I add follows expiration dates through
                      Code:
                      Instrument.MasterInstrument.RollOverCollection[i].ContractMonth
                      Add(instName, PeriodType.Day, 1)
                      so now I added:
                      CL 12-13
                      CL 01-14
                      CL 02-14
                      CL 03-14
                      CL 04-14
                      CL 05-14
                      CL 06-14
                      CL 07-14
                      CL 08-14
                      CL 09-14
                      CL 10-14

                      After this I'd like to add another instrument let's say ZS. But how can I add if I don't know what is the earliest delivery date of the future (ZS) (I don't know it it is 11-13 or 12-13 etc.)
                      And I can't use BarsArray[1] because ZS is not added yet.

                      There is also problem taht I can't use BarsArray[1] in Initialize and Add() can be used only in Initialize.
                      So How can I find out the earliest delivery date of a new Instrument (ZS, ES, ets..)??

                      Thank you in advance.
                      Last edited by Luigio; 09-19-2013, 04:29 AM.

                      Comment


                        #12
                        Luigio,

                        Please note that this kind of coding is unsupported.

                        With that being said let me try some testing on my end and see if I can get a workable solution for you.

                        If you happen to find a way before I report go ahead and post it.
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          Luigio,

                          Thank you for your patience.

                          I have been testing on our side and consulted with my fellow NinjaScript colleagues.

                          In your case of what you are trying to accomplish this would not be possible with any of the supported code that I could offer you.

                          However, I will leave the thread open for the rest of the forum community who may be able to help you out.

                          Let me know if I can be of further assistance.
                          Cal H.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello,
                            It would solve this problem to be able to use BarsArray[] in Initialize() method or Add() in the rest of the code lets say in OnStartUp(). Or to call Intitialize() from code and just proceed a part of the method (conditions), but it would have to look like real calling . Do you know how to do anything of my suggestions?

                            Thank you in advance.

                            Comment


                              #15
                              Luigio,

                              I'll forward this thread to development as a feature request for the next major release of NinjaTrader.

                              Let me know if I can be of further assistance.
                              Cal H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cre8able, Today, 01:16 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post cre8able  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              3 responses
                              48 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by samish18, Today, 01:01 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by WHICKED, Today, 12:56 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by WHICKED, Today, 12:45 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X