Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How does NT handle multi timeframe instrument with contract month

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

    How does NT handle multi timeframe instrument with contract month

    I'm creating a strategy that will include a AddDataSeries of MES 1-minute. Strategy builder has taken care of the details of that.

    I'm wondering what happens at expiry? When we roll over to a new contract symbol, since the strategy must be compiled before running, will the code need to be edited and recompiled manually? Should I include a text box in parameters to enter a new contract symbol to eliminate the need for recompiling?

    #2
    Hello Chippy,

    Thanks for your post.

    If you add another symbol with the Strategy Builder the string used in AddDataSeries will contain the expiry you chose in the Strategy Builder.

    If you check "Use Primary Instrument," the primary data series will be used so we would not have to worry about another expiry being used.

    The strategy would need to be edited when you rollover so the symbol in AddDataSeries uses the new expiry of that symbol.

    As a tip, you could consider writing a method that could fetch the current expiry (as seen in NinjaTrader's instrument database, this is not based on volume) if you provide the name of the futures symbol. AddDataSeries is called in State.Configure and user inputs are not guaranteed to be present at that state.

    For example, the method below would return "CL -05-22" if you gave it "CL" That return value could be used in AddDataSeries.

    Code:
    private string GetCurrentFuture(string name)
    {
        foreach (Instrument inst in Instrument.All)
        {
            if (inst.MasterInstrument.Name == name && inst.MasterInstrument.InstrumentType == InstrumentType.Future)
            {
                string instFullName = String.Format("{0} {1}-{2}",
                                name,
                                inst.MasterInstrument.GetNextExpiry(Core.Globals.Now).Month.ToString("D2"),
                                inst.MasterInstrument.GetNextExpiry(Core.Globals.Now).ToString("yy"));
                return instFullName;
            }
        }
        return name;
    }
    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Great! Thank you! So, I simply write in a call to the method on the line preceding the AddDataSeries?

      Maybe I'm going about this all wrong. I didn't expect to have to edit the strategy every rollover. It would be nice if I could select the instrument and expiry from the parameters, but I'm open to other suggestions. To be clear, it would be nice if the instruments and expiry didn't need to be hard coded, but my immediate intent was to create a strategy that compares the values from my custom indicator that is running on two different time frames of ES. The instrument is the same. Both data sets would be from two different time frames. My custom indicator uses T&S data stream. Would I be better off just parsing the tick data from the Primary Instrument for my secondary time frame?

      Comment


        #4
        Hello Chippy,

        The method returns a string of "CL 05-22" if you give it "CL"

        The returned string "CL 05-22" can be used as the instrument parameter in AddDataSeries.

        If you have the Use Primary Data Series tick box checked, the instrument name (including the expiry) from the primary data series would be used. You would not have to worry about editting a strategy to update the expiry in this case.

        Separate instruments are a different case. NinjaTrader does not know the expiry you will want to use (we rollover based on dates not specifically on active volume between expiries) so with other instruments, the instrument name has to be hard coded.

        The snippet I gave can get the most recent expiry for the symbol, so you do not have to edit every rollover, but this does not mean the next expiry has the most trading volume.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by yubo27, 12-01-2023, 09:32 AM
        10 responses
        259 views
        0 likes
        Last Post judysamnt7  
        Started by thehammer, 12-18-2023, 08:51 PM
        10 responses
        249 views
        0 likes
        Last Post judysamnt7  
        Started by Rosa Riley, Today, 05:44 AM
        0 responses
        10 views
        0 likes
        Last Post Rosa Riley  
        Started by giogio1, 12-01-2024, 08:49 PM
        4 responses
        20 views
        0 likes
        Last Post giogio1
        by giogio1
         
        Started by rokups, 12-01-2024, 05:44 AM
        2 responses
        25 views
        0 likes
        Last Post rokups
        by rokups
         
        Working...
        X