Announcement

Collapse
No announcement yet.

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.

            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 Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                618 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                359 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                105 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                561 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                566 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X