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

How do I get the instrument name of the chart I am running a strategy on?

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

    How do I get the instrument name of the chart I am running a strategy on?

    Hi there,

    Say I am running a strategy on Instrument A.

    If I only have Instrument A in my account, I want to add more Instrument A.
    If I have Instrument B and Instrument C in my account, I will not add Instrument A.

    Which method can I use to get Instrument A (which my chart is running on) via ninjascript for comparing?

    #2
    Hello ellrion,

    Thank you for your post.

    Please clarify your inquiry so I may better understand and assist you. When you refer to having instrument A in your account, for example, do you mean having an open position on that instrument? By "add more instrument A" what do you mean? What do you plan to add?

    Do you plan to use this NinjaScript method inside of the same script that has instruments A, B, C, etc in it or are you trying to get account information from other running strategies in a separate script?

    I look forward to assisting you further.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Emily View Post
      Hello ellrion,

      Thank you for your post.

      Please clarify your inquiry so I may better understand and assist you. When you refer to having instrument A in your account, for example, do you mean having an open position on that instrument? By "add more instrument A" what do you mean? What do you plan to add?

      Do you plan to use this NinjaScript method inside of the same script that has instruments A, B, C, etc in it or are you trying to get account information from other running strategies in a separate script?

      I look forward to assisting you further.
      Hi Emily,

      Apologize for the lousy example given. Basically I just need to get the instrument name of the chart where I ran my strategy in.
      I manage to get this by using
      string myInstrumentName = this.Instrument.FullName
      .

      I am using this as part of my logging string as I am running the same strategy on different instruments. With 2 charts sending the logs to the common log tab, it can get confusing.

      Comment


        #4
        Hello elirion,

        Thank you for your reply.

        I appreciate the additional information. What you are using could work to meet your needs, or if you would like to get the instrument name based on the Bars being updated in OnBarUpdate() you could use something like the following:
        Code:
        Bars.Instrument.MasterInstrument.Name


        As for logging to the log tab, it is extremely important to keep in mind potential performance impacts. See the warning in the help guide here:
        • https://ninjatrader.com/support/helpGuides/nt8/log.htm
          • Warning: Each call to this method creates a log entry which takes memory to keep loaded in the Log tab of the Control Center. Excessive logging can result in huge portions of memory being allocated to display the log messages.
        Log entries are not deleted/removed, so the more items that are logged, the more memory is used. As a more performance-friendly alternative we highly recommend using Print() instead to print information to the NinjaScript Output window. The NinjaScript Output window has a maximum number of lines that will display, so any older lines once that max is reached will be deleted/cleared to free up memory. You can even use PrintTo to set the prints for a script to go to either the Output 1 tab or the Output 2 tab:If you need to maintain all of the information that you are sending as output rather than having the oldest lines deleted in the NinjaScript Output window, you could consider using StreamWriter to write text to a text file. Then you could refer back to the text file for the output information rather than having the performance impact of that information being sent to the NinjaTrader Log tab. We have a relevant reference sample here:Please let us know if we may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          NinjaTrader_Emily

          Can't thank you enough for the additional tips on logging. Definitely helpful for newer ninjascripts developer like me.
          Cheers and have a great weekend ahead

          Comment


            #6
            Hi there.

            Print() is working nicely for me. The only thing is that I can see other categories such as "Position", "Order" and "Execution" within Log tab. Are we able to also direct these information to the NinjaScript Output Windows too? So that I have a common place to look at all related logs.

            Comment


              #7
              Hello elirion,

              Thank you for your reply.

              That information is sent to the Log internally by the platform. If you'd like to add Position, Order, and Execution information to your logs you could consider adding prints from OnPositionUpdate(), OnOrderUpdate(), and OnExecutionUpdate() or print information from position/order/execution objects:Please let us know if we may be of further assistance.
              Emily C.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cmtjoancolmenero, Yesterday, 05:05 PM
              5 responses
              36 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by trilliantrader, Today, 07:50 AM
              1 response
              2 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by Taddypole, Yesterday, 02:25 PM
              3 responses
              19 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by NM_eFe, 04-30-2024, 06:14 AM
              6 responses
              36 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
              27 responses
              92 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X