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 funk10101, Today, 09:43 PM
            0 responses
            2 views
            0 likes
            Last Post funk10101  
            Started by pkefal, 04-11-2024, 07:39 AM
            11 responses
            36 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Yesterday, 08:51 AM
            8 responses
            44 views
            0 likes
            Last Post bill2023  
            Started by yertle, Today, 08:38 AM
            6 responses
            25 views
            0 likes
            Last Post ryjoga
            by ryjoga
             
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            24 views
            0 likes
            Last Post algospoke  
            Working...
            X