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

Instrument Name?

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

    Instrument Name?

    I'm trying to print out (with StreamWriter) the instrument name to the file name (i.e., if I'm printing out the trades of SPY, the file will be called SPY).
    I tried to do so using the property Instrument.MasterInstrument.Name, with no result both in StreamWriter and Print().
    Which syntax should I use in the StreamWriter to be able to print out as file name the ticker I'm currently using?
    In your example it was
    private string path = Cbi.Core.UserDataDir.ToString() + "MyTestFile.txt";

    I'd like to achieve something like private string path = Cbi.Core.UserDataDir.ToString() + "SPY.txt";

    if I'm currently running the StreamWriter on SPY.

    Many thanks!

    #2
    private string path = Cbi.Core.UserDataDir.ToString() + Instrument.MasterInstrument.Name + ".txt";
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I copied and pasted that into your sample, but I got the following error compiling the code:
      An object reference is required for the nonstatic field, method, or property 'NinjaTrader.Cbi.Instrument.MasterInstrument.get CS0120 - click for info

      Comment


        #4
        You need to make sure you are doing it in the right place. Please do it in OnBarUpdate().

        if (CurrentBar == 0)
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          You need to make sure you are doing it in the right place. Please do it in OnBarUpdate().

          if (CurrentBar == 0)
          I want to get the name of the instrument when the Initialize function is called. This is to setup some external libraries.

          Is there a way to do that? Doing it in OnBarUpdate() is too late and also very expensive computationally.

          Comment


            #6
            Unfortunately not, please do it on the first OnBarUpdate bar as Josh pointed out.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              I am running a multi-series strategy and want to create an output file that has the instrument as part of its name. I've placed the code in OnBarUpdate as follows:

              if (BarsInProgress == 0)
              {
              if (CurrentBar == 0)
              {
              private string path = Cbi.Core.UserDataDir.ToString() + Instrument.FullName + ".txt";
              }
              }
              However, the main error I'm getting is "Statement expected." There are then a lot of other errors, namely "identifier expected." Has anyone figured out a way to include the instrument name in the output file? Thank you!
              Last edited by cb4gusto22; 05-07-2015, 01:38 PM. Reason: make more clear

              Comment


                #8
                Hello cb4gusto22,
                Thanks for posting today.

                Remove the "private" access modifier from the statement.

                Code:
                private string path = Cbi.Core.UserDataDir.ToString() + Instrument.FullName + ".txt";
                This will allow this statement to compile and should assign the correct instrument name to the string path.

                Please let us know if we may be of further assistance for anything NinjaTrader.
                Alex G.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                26 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 02-22-2024, 01:11 AM
                5 responses
                32 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 04-23-2024, 09:53 PM
                2 responses
                49 views
                0 likes
                Last Post wzgy0920  
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                193 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,235 views
                0 likes
                Last Post xiinteractive  
                Working...
                X