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 cre8able, Yesterday, 01:16 PM
            3 responses
            11 views
            0 likes
            Last Post cre8able  
            Started by ChartTourist, Today, 08:22 AM
            0 responses
            5 views
            0 likes
            Last Post ChartTourist  
            Started by LiamTwine, Today, 08:10 AM
            0 responses
            2 views
            0 likes
            Last Post LiamTwine  
            Started by Balage0922, Today, 07:38 AM
            0 responses
            5 views
            0 likes
            Last Post Balage0922  
            Started by JoMoon2024, Today, 06:56 AM
            0 responses
            6 views
            0 likes
            Last Post JoMoon2024  
            Working...
            X