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 rhyminkevin, Today, 04:58 PM
              3 responses
              47 views
              0 likes
              Last Post Anfedport  
              Started by iceman2018, Today, 05:07 PM
              0 responses
              5 views
              0 likes
              Last Post iceman2018  
              Started by lightsun47, Today, 03:51 PM
              0 responses
              7 views
              0 likes
              Last Post lightsun47  
              Started by 00nevest, Today, 02:27 PM
              1 response
              14 views
              0 likes
              Last Post 00nevest  
              Started by futtrader, 04-21-2024, 01:50 AM
              4 responses
              50 views
              0 likes
              Last Post futtrader  
              Working...
              X