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

Printing the Instrument name from a strategy

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

    Printing the Instrument name from a strategy

    Hi,

    In my strategy I would like to print the instrument name (using the Print method) PRIOR to sending an order.
    I was wondering what method should I call in order to get the instrument name I set in the strategy window.

    Regards,

    Ron

    #2
    Hello Ron,
    Thanks for your post and I am happy to assist you.

    You can use the following to get the name of the instrument:
    Code:
    Instrument.FullName;
    Or
    Code:
    Instrument.MasterInstrument.Name;


    Please let me know if I can assist you any further.
    Last edited by NinjaTrader_Joydeep; 02-07-2012, 12:06 PM.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Hi

      I have a strategy with several instruments, in order to debug I want to print all instrument names. However, when I print Instrument.FullName[1], then I get "A" instead the instrument name.
      Instrument.FullName alone works fine for first instrument (0-bars series)

      how can I get the name of my 2nd instrument?

      Comment


        #4
        Hello Beauregard,

        Thank you for your post.

        You'd want to use Instruments[]:



        Code:
        protected override void OnStateChange()
        {
          if (State == State.DataLoaded)
          {
              // Print all instruments which have been loaded
              foreach (Instrument i in Instruments)
              {
                  Print(i.FullName);
              }
          }
        }
        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hi Kate

          thanks, this is not exactly what I am looking for. I would like to address the instrument name directly.
          Example: I have three data series, the default one and I add 2 more:
          Add(Instrument2, PeriodType.Day, 1);
          Add(Instrument3, PeriodType.Day, 1);

          Then I have a function where I need some debug information. The function is called within OnBarUpdate.
          I would like to have the name of my Instrument2 and the Marketposition
          Print (String.Format("{0:d}",Time[0])+" "+Instrument.FullName[1]+":"+Positions[1].MarketPosition);

          This does not work

          Comment


            #6
            Hello Beauregard,

            Thank you for your reply.

            I do apologize as the link I posted was for NT8, however, the general idea is the same. You're just putting the index in the wrong spot:

            Print (String.Format("{0:d}",Time[0])+" "+Instruments[1].FullName+":"+Positions[1].MarketPosition);

            You want to make sure you're referencing the Instruments array by index before accessing the FullName property.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Great! thanks. I tried this before, but I used Instrument instead Instruments

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by AttiM, 02-14-2024, 05:20 PM
              12 responses
              213 views
              0 likes
              Last Post DrakeiJosh  
              Started by cre8able, 02-11-2023, 05:43 PM
              3 responses
              237 views
              0 likes
              Last Post rhubear
              by rhubear
               
              Started by frslvr, 04-11-2024, 07:26 AM
              8 responses
              116 views
              1 like
              Last Post NinjaTrader_BrandonH  
              Started by stafe, 04-15-2024, 08:34 PM
              10 responses
              47 views
              0 likes
              Last Post stafe
              by stafe
               
              Started by rocketman7, Today, 09:41 AM
              3 responses
              12 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X