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

Get the instrument name of the merged price series

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

    Get the instrument name of the merged price series

    I am using Merge Non Back Adjusted policy for my price series (CL Oil)
    My understanding is, for example:

    I am backtesting using CL 04-15 for period 01/01/15 till 03/11/15, which means, the price from:
    01/01/15 - 01/16/15 is grab from front contract of that time (CL-02-15);
    01/17/15 - 02/18/15 is grab from front contract of that time (CL-03-15);
    02/19/15 - 03/11/15 is grab from front contract of that time (CL-04-15);

    My question is, in OnBarUpdate() for daily bar on, ex: 13/01/15, how can I get the front contract instrument name, which is CL 02-15? Or, on 13/02/15 which is CL 03-15?

    Thanks.

    #2
    Hello Vhanded,

    Thank you for your note.

    You would need to compare the Rollover dates from the MasterInstrument to the date on the bars that you getting data from.

    A good example of how to get the Rollover collection for this is available from the link below -
    http://www.ninjatrader.com/support/f...atid=4&lpage=8

    Please note that is unsupported programming with NinjaTrader and do not have documentation on the matter
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hi Cal, thanks for you reply.

      The solution of using RollOverCollections works, I can get a list of contract of the same Instrument.

      However, I am implementing calendar spread, which require to compare price of each contract, so I can only use NoMergeBack.

      However, there seems to have certain limit of Instrument that I can add in Initialize(), here is my code:

      I am testing on ZS 01-15 for period of 1/1/2014-11/3/2015, daily bar.

      Code:
              protected override void Initialize()
              {
                  CalculateOnBarClose = true;
      			
      			
      			Add("ZS 01-15", BarsPeriod.Id, BarsPeriod.Value);
      			Add("ZS 03-15", BarsPeriod.Id, BarsPeriod.Value);
                              Add("ZS 05-15", BarsPeriod.Id, BarsPeriod.Value);
      
              }
      
      
              protected override void OnBarUpdate()
              {
      			Print("OnBarUpdate");
              }
      With this code, it will print a long list of "OnBarUpdate" in console.

      However, if I modify to:
      Code:
      Add("ZS 01-15", BarsPeriod.Id, BarsPeriod.Value);
      Add("ZS 03-15", BarsPeriod.Id, BarsPeriod.Value);
      Add("ZS 05-15", BarsPeriod.Id, BarsPeriod.Value);
      Add("ZS 07-15", BarsPeriod.Id, BarsPeriod.Value);
      then "OnBarUpdate" is not printing in console, and no error at all.

      This phenomena is happening on CL (crude oil) too.

      I already tried to delete the day, tick, minute etc folder in db, and let Continuum to redownload the price, but to no avail.

      Please help.

      Comment


        #4
        Vhanded,

        This is expected.

        When you add data series to the script it will add another bars object that will call OnBarUpdate.
        Additionally note that any future contracts that are not the current one will only grab the most current contract information due to the rollover and merge policy.

        You can change this by going to Tools -> Options -> Data Tab -> Merge Policy -> DoNotMerge
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Hi Cal,

          I understand well about the merge policy, and I already set my merge policy to DoNotMerge.

          And I also understand that Add() a new instrument in Initialize() will create a new Bars object that will call OnBarUpdate().

          My question is, why after I added "ZS 07-15", the OnBarUpdate() is not fire anymore?

          Comment


            #6
            Vhanded,

            Thanks for the clarification.

            There is no limit to how many you can add to the script.

            Are there no errors in the log tab when you start it?
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              No error at all. Can you able to reproduce it on your side?

              I tried on CL too, I added CL 03-15, 04-15, 05-15, 06-15, 07-15, and stop working at 08-15.

              Comment


                #8
                I also tried by adding just ZS 07-15, no others, it failed to run OnBarUpdate() too.

                Comment


                  #9
                  Vhanded,

                  I'm not getting this issue on my end.

                  Can you attach the script that you are using so I can compare to my end?
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    I attached the version of code that will not fire OnBarUpdate().

                    Please backtest it on instrument ZS 01-15, from 1/1/2015 - 3/11/2015, using daily bar.

                    Thanks.
                    Attached Files

                    Comment


                      #11
                      Vhanded,

                      That's because you are using 01-15 instrument which rolled over in January. There is not enough data during that time since the rollover date.

                      If you expand it back to December 1st, 2014 that should get you enough data
                      Cal H.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Cal, thanks for your reply. You are right, but I also realize, to successfully backtest for a year, I can't use a specific contract month. I can only use ZS ##-##.

                        However, this means, when there is 1 instrument month does not fit into the backtest period, the whole process dont run at all without any error.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by andrewtrades, Today, 04:57 PM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by chbruno, Today, 04:10 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post chbruno
                        by chbruno
                         
                        Started by josh18955, 03-25-2023, 11:16 AM
                        6 responses
                        436 views
                        0 likes
                        Last Post Delerium  
                        Started by FAQtrader, Today, 03:35 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post FAQtrader  
                        Started by rocketman7, Today, 09:41 AM
                        5 responses
                        19 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Working...
                        X