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

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 burtoninlondon, Today, 12:38 AM
        0 responses
        5 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        12 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        11 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Yesterday, 07:51 PM
        0 responses
        13 views
        0 likes
        Last Post strategist007  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        44 responses
        3,982 views
        3 likes
        Last Post jhudas88  
        Working...
        X