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

Get Current Symbol Future in NinjaScript

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

    Get Current Symbol Future in NinjaScript

    Hi,

    How can I get the current symbol for a future instrument ?

    I have a multi-instrument strategy and i look for something like GetInstrument(instrumentName), for example:

    GetInstrument("MNQ") returns "MNQ 09-20";
    GetInstrument("MES") returns "MES 09-20";

    Is this possible ?

    Thanks.

    #2
    Hello brunoviveiros,

    The script you are using already has a Instrument property which is assigned to whatever BarsInProgress was called at that time. The property is just "Instrument":



    In the help guide this section is a little confusing, you actually need to go into one of the sub property pages like FullName to see a sample of the Instrument object. Keep in mind this would be used later in your script once it is loaded, this should not be used for trying to add dynamic data. In general this should not be used before State.DataLoaded: https://ninjatrader.com/support/help...instrument.htm


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

    Comment


      #3
      Hi, Jesse!

      Thanks for your reply.

      I need get the currenty symbol to add the instruments in AddDataSeries method.
      This way, i dont need use a function to calculate the current symbol.

      Is this possible?

      Comment


        #4
        Hello brunoviveiros,

        There is currently no supported way to dynamically add data series.While some users have done this it does not work in all tools and has a mixed result. You would need to specify the name as a string which is not a user or runtime variable.

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

        Comment


          #5
          Hi, Jesse!

          I managed to get the current symbol through the code below:

          Instrument ins = Instrument.All.Where(x => x.MasterInstrument.Name == strInstrumentName && x.MasterInstrument.InstrumentType == InstrumentType.Future && x.Expiry.Date > DateTime.Now).OrderBy(o => o.Expiry.Date).First();

          Where strInstrumentName is the name of the desired instrument, for example "MES".

          Tks!

          Comment


            #6
            Hi, Jesse!

            I have a AWS instance that runs my strategy for 24hrs. and that strategy trades in MNQ future.
            There is some way to change the DataSeries without disable my strategy ?

            Example:
            In the rollover date (2020/06/11) for MNQ 09-20, I need to trade a new contract for MNQ, that is MNQ 12-20.
            Add a new DataSeries not is possible, because this method only be called to State.Configure.
            How can i do that without disable my strategy ?

            This behavior will let me automatizate the contract changes without manual intervetion.

            Comment


              #7
              Hello brunoviveiros,

              There is not a way to dynamically manage the dataseries from a strategy, it would need to be specified when you enable it or in code as you noted.

              An addon could in theory do this using BarsRequests and subscribing/unsubscribing from the various instruments/contracts but this is not something which would be supported in a strategy specifically you would just migrate to an addon for that type of use case.

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

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by terofs, Yesterday, 04:18 PM
              1 response
              21 views
              0 likes
              Last Post terofs
              by terofs
               
              Started by CommonWhale, Today, 09:55 AM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by Gerik, Today, 09:40 AM
              2 responses
              7 views
              0 likes
              Last Post Gerik
              by Gerik
               
              Started by RookieTrader, Today, 09:37 AM
              2 responses
              13 views
              0 likes
              Last Post RookieTrader  
              Started by alifarahani, Today, 09:40 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X