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

Add another instrument to my indicator

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

    Add another instrument to my indicator

    Hi I'm adding the "ES" to an indicator that I run off my TF chart. Below is my code:

    Add("ES 12-14", PeriodType.Tick, 400);

    How do I code it so that it always selects the most current ES contract?

    Thanks

    #2
    Hello,

    Thank you for the question.

    For that statement you would want to use the instruments full name or:

    Add(Instrument.FullName, PeriodType.Tick, 400);

    There is also a Name located in Instrument but this does not include futures contract date.

    This will provide the name of whatever instrument the indicator is applied to.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      thanks ... to clarify, I'm running this indicator on a TF chart (not an ES chart) but I want to check a certain condition on the ES ... so how do I point it to the most current ES instrument?

      Comment


        #4
        Hello,

        Thank you for clarifying.

        For this if the instrument has the same rollover date, you can try to use Instrument.Expiry but anything in Initalize() we generally recommend to hard code these values.

        I believe you would need to use a string "ES " + Instrument.Expiry for this to work, you would want to use a Print() statement to output to the output window to ensure the string that is generated is exactly the same as the instrument name.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          can you direct me to an example

          Comment


            #6
            Hello,

            We dont really have a specific example for this as its not really a supported way of doing things.

            I will provide this, this should work in most situations, you would fill in the "Static" instrument name such as TF and then the expiry will be appended to the string with the commands that follow

            Code:
            	Print("TF " + Instrument.Expiry.Month + "-" + Instrument.Expiry.Year.ToString().Substring(2, 2));
            The substring is needed as it returns the date as 2014, the substring is just saying cut the text after 2 characters and cut 2 characters or the last 2 numbers of the date.

            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,789 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            837 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,293 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            13 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            63 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X