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

Attach Instrument to script

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

    Attach Instrument to script

    Hello,

    I´m working with parameters for years in NT7 using for doubles, ints and strings. All works ok.

    Today I tried to use the string in parameters also for adding instruments so that we dont need to change it in the code. But when enabling the script I get the error-message

    14.06.2019 03:51:02 Strategy The strategy 'TxMultiLSv12/64276884a61e42b8b5fac9e16171dd7b' has called the Add() method with an invalid instrument. Either 'instrument1' does not exist in the Instrument Manager or the specified exchange has not been configured.

    Of course instrument1 doest not exist, but in parameters I fill eg NQ 06-19 and its causing the message.

    Is there something special when adding instruments with string from parameters to Initialize?

    Thank you!
    Tony

    #2
    Hello tonynt,

    Thanks for your post.

    Please show the line of code where you have specified Instrument1 and then the line that shows the Add() method with instrument1.

    Thank-you.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello Paul,

      thank you for your reply. Please see attached the screenshotsof the script in NT7.

      Thank you!
      Tony
      Attached Files
      Last edited by tonynt; 06-14-2019, 07:01 AM. Reason: upload error

      Comment


        #4
        Hello tonynt,

        Thanks for your reply.

        In the add() statement you are adding the string "instrument1" which is being taken as the literal instrument name and what you need would be the variable named instrument1 that is a string with the instrument name that you are inputting. IE change Add("instrument1", PeriodType.Minute, 1) to Add(instrument1, PeriodType.Minute, 1)
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello Paul,

          thank you for your reply. Now NT shoots me a message when I have one of the instruments parameter empty. How can we do when we have 4 instruments in parameters but only want to use 3 this day to avoid this error message from empty parameter.

          Thank you!
          Tony
          Last edited by tonynt; 06-14-2019, 07:24 AM.

          Comment


            #6
            Hello tonynt,

            Thanks for your reply.

            You are setting the variables with the string that is the same name as the variable so you can use that in an if statement:

            if (instrument4 != "instrument4") // making the assumption that if the variable instrument4 does not contain "instrument4" it must contain a legit instrument name
            Add(instrument4, PeriodType.Minute, 1);


            NOTE: If you do not add a 4th instrument, make sure you account for this in your OnBarUpdate() because if you have references to that 4th instrument and no data then you will get object not found type errors.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mizzouman1, Today, 07:35 AM
            3 responses
            17 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by RubenCazorla, Today, 09:07 AM
            2 responses
            13 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by i019945nj, 12-14-2023, 06:41 AM
            7 responses
            82 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by timmbbo, 07-05-2023, 10:21 PM
            4 responses
            158 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by tkaboris, Today, 08:01 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X