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 frslvr, 04-11-2024, 07:26 AM
                9 responses
                121 views
                1 like
                Last Post caryc123  
                Started by rocketman7, Today, 09:41 AM
                4 responses
                15 views
                0 likes
                Last Post rocketman7  
                Started by selu72, Today, 02:01 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by WHICKED, Today, 02:02 PM
                2 responses
                15 views
                0 likes
                Last Post WHICKED
                by WHICKED
                 
                Started by f.saeidi, Today, 12:14 PM
                8 responses
                21 views
                0 likes
                Last Post f.saeidi  
                Working...
                X